From a5ba3255838b1580667935ecd96b1a9b5b8814b0 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 2 Apr 2019 19:19:01 -0400 Subject: [PATCH] Fix health issues --- angel_orm/analysis_options.yaml | 1 + angel_orm/lib/src/annotations.dart | 6 ++--- angel_orm/lib/src/builder.dart | 10 +++---- angel_orm/lib/src/migration.dart | 4 +-- angel_orm/lib/src/query.dart | 42 ++++++++++++++++-------------- angel_orm/lib/src/relations.dart | 15 ++++++----- angel_orm/pubspec.yaml | 1 + 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/angel_orm/analysis_options.yaml b/angel_orm/analysis_options.yaml index eae1e42a..c230cee7 100644 --- a/angel_orm/analysis_options.yaml +++ b/angel_orm/analysis_options.yaml @@ -1,3 +1,4 @@ +include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false \ No newline at end of file diff --git a/angel_orm/lib/src/annotations.dart b/angel_orm/lib/src/annotations.dart index f5976d73..3231bf23 100644 --- a/angel_orm/lib/src/annotations.dart +++ b/angel_orm/lib/src/annotations.dart @@ -11,7 +11,7 @@ class Orm { /// Defaults to [:true:]. final bool generateMigrations; - const Orm({this.tableName, this.generateMigrations: true}); + const Orm({this.tableName, this.generateMigrations = true}); } @deprecated @@ -20,8 +20,8 @@ class Join { final String foreignKey; final JoinType type; - const Join(this.against, this.foreignKey, {this.type: JoinType.inner}); + const Join(this.against, this.foreignKey, {this.type = JoinType.inner}); } -/// The various types of [Join]. +/// The various types of join. enum JoinType { inner, left, right, full, self } diff --git a/angel_orm/lib/src/builder.dart b/angel_orm/lib/src/builder.dart index 1f13ac28..c3cb8908 100644 --- a/angel_orm/lib/src/builder.dart +++ b/angel_orm/lib/src/builder.dart @@ -372,23 +372,23 @@ class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder { operator >=(DateTime value) => _change('>=', value, true); - void equals(DateTime value, {bool includeTime: true}) { + void equals(DateTime value, {bool includeTime = true}) { _change('=', value, includeTime != false); } - void lessThan(DateTime value, {bool includeTime: true}) { + void lessThan(DateTime value, {bool includeTime = true}) { _change('<', value, includeTime != false); } - void lessThanOrEqualTo(DateTime value, {bool includeTime: true}) { + void lessThanOrEqualTo(DateTime value, {bool includeTime = true}) { _change('<=', value, includeTime != false); } - void greaterThan(DateTime value, {bool includeTime: true}) { + void greaterThan(DateTime value, {bool includeTime = true}) { _change('>', value, includeTime != false); } - void greaterThanOrEqualTo(DateTime value, {bool includeTime: true}) { + void greaterThanOrEqualTo(DateTime value, {bool includeTime = true}) { _change('>=', value, includeTime != false); } diff --git a/angel_orm/lib/src/migration.dart b/angel_orm/lib/src/migration.dart index d5edd31f..b96ce517 100644 --- a/angel_orm/lib/src/migration.dart +++ b/angel_orm/lib/src/migration.dart @@ -27,10 +27,10 @@ class Column { final IndexType indexType; const Column( - {this.isNullable: true, + {this.isNullable = true, this.length, this.type, - this.indexType: IndexType.none}); + this.indexType = IndexType.none}); } class PrimaryKey extends Column { diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index 5f4dc7ff..c9196ad9 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -28,7 +28,7 @@ abstract class QueryBase { }).join(', '); String compile(Set trampoline, - {bool includeTableName: false, String preamble, bool withFields: true}); + {bool includeTableName = false, String preamble, bool withFields = true}); T deserialize(List row); @@ -56,7 +56,7 @@ class OrderBy { final String key; final bool descending; - const OrderBy(this.key, {this.descending: false}); + const OrderBy(this.key, {this.descending = false}); String compile() => descending ? '$key DESC' : '$key ASC'; } @@ -64,7 +64,7 @@ class OrderBy { /// The ORM prefers using substitution values, which allow for prepared queries, /// and prevent SQL injection attacks. @deprecated -String toSql(Object obj, {bool withQuotes: true}) { +String toSql(Object obj, {bool withQuotes = true}) { if (obj is DateTime) { return withQuotes ? "'${dateYmdHms.format(obj)}'" : dateYmdHms.format(obj); } else if (obj is bool) { @@ -147,7 +147,7 @@ abstract class Query extends QueryBase { } /// Determines whether this query can be compiled. - /// + /// /// Used to prevent ambiguities in joins. bool canCompile(Set trampoline) => true; @@ -188,7 +188,7 @@ abstract class Query extends QueryBase { } /// Sorts the results by a key. - void orderBy(String key, {bool descending: false}) { + void orderBy(String key, {bool descending = false}) { _orderBy.add(new OrderBy(key, descending: descending)); } @@ -250,8 +250,8 @@ abstract class Query extends QueryBase { /// Execute an `INNER JOIN` against another table. void join(tableName, String localKey, String foreignKey, - {String op: '=', - List additionalFields: const [], + {String op = '=', + List additionalFields = const [], Set trampoline}) { _makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op, additionalFields); @@ -259,8 +259,8 @@ abstract class Query extends QueryBase { /// Execute a `LEFT JOIN` against another table. void leftJoin(tableName, String localKey, String foreignKey, - {String op: '=', - List additionalFields: const [], + {String op = '=', + List additionalFields = const [], Set trampoline}) { _makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op, additionalFields); @@ -268,8 +268,8 @@ abstract class Query extends QueryBase { /// Execute a `RIGHT JOIN` against another table. void rightJoin(tableName, String localKey, String foreignKey, - {String op: '=', - List additionalFields: const [], + {String op = '=', + List additionalFields = const [], Set trampoline}) { _makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op, additionalFields); @@ -277,8 +277,8 @@ abstract class Query extends QueryBase { /// Execute a `FULL OUTER JOIN` against another table. void fullOuterJoin(tableName, String localKey, String foreignKey, - {String op: '=', - List additionalFields: const [], + {String op = '=', + List additionalFields = const [], Set trampoline}) { _makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op, additionalFields); @@ -286,8 +286,8 @@ abstract class Query extends QueryBase { /// Execute a `SELF JOIN`. void selfJoin(tableName, String localKey, String foreignKey, - {String op: '=', - List additionalFields: const [], + {String op = '=', + List additionalFields = const [], Set trampoline}) { _makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op, additionalFields); @@ -295,9 +295,9 @@ abstract class Query extends QueryBase { @override String compile(Set trampoline, - {bool includeTableName: false, + {bool includeTableName = false, String preamble, - bool withFields: true, + bool withFields = true, String fromQuery}) { // One table MAY appear multiple times in a query. if (!canCompile(trampoline)) { @@ -556,7 +556,7 @@ class Union extends QueryBase { @override final String tableName; - Union(this.left, this.right, {this.all: false, String tableName}) + Union(this.left, this.right, {this.all = false, String tableName}) : this.tableName = tableName ?? left.tableName { substitutionValues ..addAll(left.substitutionValues) @@ -571,7 +571,9 @@ class Union extends QueryBase { @override String compile(Set trampoline, - {bool includeTableName: false, String preamble, bool withFields: true}) { + {bool includeTableName = false, + String preamble, + bool withFields = true}) { var selector = all == true ? 'UNION ALL' : 'UNION'; var t1 = Set.from(trampoline); var t2 = Set.from(trampoline); @@ -587,7 +589,7 @@ class JoinBuilder { final List additionalFields; JoinBuilder(this.type, this.from, this.to, this.key, this.value, - {this.op: '=', this.alias, this.additionalFields: const []}) { + {this.op = '=', this.alias, this.additionalFields = const []}) { assert(to != null, 'computation of this join threw an error, and returned null.'); } diff --git a/angel_orm/lib/src/relations.dart b/angel_orm/lib/src/relations.dart index 585018a5..b27228a4 100644 --- a/angel_orm/lib/src/relations.dart +++ b/angel_orm/lib/src/relations.dart @@ -21,10 +21,10 @@ class Relationship { class HasMany extends Relationship { const HasMany( - {String localKey: 'id', + {String localKey = 'id', String foreignKey, String foreignTable, - bool cascadeOnDelete: false}) + bool cascadeOnDelete = false}) : super(RelationshipType.hasMany, localKey: localKey, foreignKey: foreignKey, @@ -36,10 +36,10 @@ const HasMany hasMany = const HasMany(); class HasOne extends Relationship { const HasOne( - {String localKey: 'id', + {String localKey = 'id', String foreignKey, String foreignTable, - bool cascadeOnDelete: false}) + bool cascadeOnDelete = false}) : super(RelationshipType.hasOne, localKey: localKey, foreignKey: foreignKey, @@ -63,11 +63,12 @@ class ManyToMany extends Relationship { final Type through; const ManyToMany(this.through, - {String localKey: 'id', + {String localKey = 'id', String foreignKey, String foreignTable, - bool cascadeOnDelete: false}) - : super(RelationshipType.hasMany, // Many-to-Many is actually just a hasMany + bool cascadeOnDelete = false}) + : super( + RelationshipType.hasMany, // Many-to-Many is actually just a hasMany localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, diff --git a/angel_orm/pubspec.yaml b/angel_orm/pubspec.yaml index fd8d4c5b..d89d0732 100644 --- a/angel_orm/pubspec.yaml +++ b/angel_orm/pubspec.yaml @@ -15,4 +15,5 @@ dev_dependencies: angel_serialize: ^2.0.0 angel_serialize_generator: ^2.0.0 build_runner: ^1.0.0 + pedantic: ^1.0.0 test: ^1.0.0