From 2349cc3b4e923cd9d384672de98908e6c6624df0 Mon Sep 17 00:00:00 2001 From: Matej Valenta Date: Tue, 21 Jan 2025 10:21:52 +0100 Subject: [PATCH] chore: update and fixes for dcm linter --- examples/drift/lib/db.drift.dart | 285 ++++++++++++++++++ .../freezed/lib/freezed_example.freezed.dart | 17 +- examples/injectable/lib/getit.config.dart | 16 +- packages/auto_mappr/analysis_options.yaml | 13 +- packages/auto_mappr/dcm_baseline.json | 22 +- .../iterable_assignment_builder.dart | 14 +- .../assignments/map_assignment_builder.dart | 30 +- .../assignments/nested_object_mixin.dart | 4 +- .../record_assignment_builder.dart | 12 +- .../builder/map_bodies/enum_body_builder.dart | 4 +- .../src/builder/value_assignment_builder.dart | 6 +- .../src/generator/auto_mappr_generator.dart | 16 +- .../lib/src/models/source_assignment.dart | 1 + 13 files changed, 367 insertions(+), 73 deletions(-) diff --git a/examples/drift/lib/db.drift.dart b/examples/drift/lib/db.drift.dart index 1880bdb..0a5d885 100644 --- a/examples/drift/lib/db.drift.dart +++ b/examples/drift/lib/db.drift.dart @@ -1,3 +1,4 @@ +// dart format width=80 // ignore_for_file: type=lint part of 'db.dart'; @@ -157,6 +158,15 @@ class Todo extends DataClass implements Insertable { content: content ?? this.content, category: category.present ? category.value : this.category, ); + Todo copyWithCompanion(TodosCompanion data) { + return Todo( + id: data.id.present ? data.id.value : this.id, + title: data.title.present ? data.title.value : this.title, + content: data.content.present ? data.content.value : this.content, + category: data.category.present ? data.category.value : this.category, + ); + } + @override String toString() { return (StringBuffer('Todo(') @@ -361,6 +371,14 @@ class Category extends DataClass implements Insertable { id: id ?? this.id, description: description ?? this.description, ); + Category copyWithCompanion(CategoriesCompanion data) { + return Category( + id: data.id.present ? data.id.value : this.id, + description: + data.description.present ? data.description.value : this.description, + ); + } + @override String toString() { return (StringBuffer('Category(') @@ -432,6 +450,7 @@ class CategoriesCompanion extends UpdateCompanion { abstract class _$MyDatabase extends GeneratedDatabase { _$MyDatabase(QueryExecutor e) : super(e); + $MyDatabaseManager get managers => $MyDatabaseManager(this); late final $TodosTable todos = $TodosTable(this); late final $CategoriesTable categories = $CategoriesTable(this); @override @@ -440,3 +459,269 @@ abstract class _$MyDatabase extends GeneratedDatabase { @override List get allSchemaEntities => [todos, categories]; } + +typedef $$TodosTableCreateCompanionBuilder = TodosCompanion Function({ + Value id, + required String title, + required String content, + Value category, +}); +typedef $$TodosTableUpdateCompanionBuilder = TodosCompanion Function({ + Value id, + Value title, + Value content, + Value category, +}); + +class $$TodosTableFilterComposer extends Composer<_$MyDatabase, $TodosTable> { + $$TodosTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnFilters(column)); + + ColumnFilters get title => $composableBuilder( + column: $table.title, builder: (column) => ColumnFilters(column)); + + ColumnFilters get content => $composableBuilder( + column: $table.content, builder: (column) => ColumnFilters(column)); + + ColumnFilters get category => $composableBuilder( + column: $table.category, builder: (column) => ColumnFilters(column)); +} + +class $$TodosTableOrderingComposer extends Composer<_$MyDatabase, $TodosTable> { + $$TodosTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get title => $composableBuilder( + column: $table.title, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get content => $composableBuilder( + column: $table.content, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get category => $composableBuilder( + column: $table.category, builder: (column) => ColumnOrderings(column)); +} + +class $$TodosTableAnnotationComposer + extends Composer<_$MyDatabase, $TodosTable> { + $$TodosTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => + $composableBuilder(column: $table.id, builder: (column) => column); + + GeneratedColumn get title => + $composableBuilder(column: $table.title, builder: (column) => column); + + GeneratedColumn get content => + $composableBuilder(column: $table.content, builder: (column) => column); + + GeneratedColumn get category => + $composableBuilder(column: $table.category, builder: (column) => column); +} + +class $$TodosTableTableManager extends RootTableManager< + _$MyDatabase, + $TodosTable, + Todo, + $$TodosTableFilterComposer, + $$TodosTableOrderingComposer, + $$TodosTableAnnotationComposer, + $$TodosTableCreateCompanionBuilder, + $$TodosTableUpdateCompanionBuilder, + (Todo, BaseReferences<_$MyDatabase, $TodosTable, Todo>), + Todo, + PrefetchHooks Function()> { + $$TodosTableTableManager(_$MyDatabase db, $TodosTable table) + : super(TableManagerState( + db: db, + table: table, + createFilteringComposer: () => + $$TodosTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => + $$TodosTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$TodosTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: ({ + Value id = const Value.absent(), + Value title = const Value.absent(), + Value content = const Value.absent(), + Value category = const Value.absent(), + }) => + TodosCompanion( + id: id, + title: title, + content: content, + category: category, + ), + createCompanionCallback: ({ + Value id = const Value.absent(), + required String title, + required String content, + Value category = const Value.absent(), + }) => + TodosCompanion.insert( + id: id, + title: title, + content: content, + category: category, + ), + withReferenceMapper: (p0) => p0 + .map((e) => (e.readTable(table), BaseReferences(db, table, e))) + .toList(), + prefetchHooksCallback: null, + )); +} + +typedef $$TodosTableProcessedTableManager = ProcessedTableManager< + _$MyDatabase, + $TodosTable, + Todo, + $$TodosTableFilterComposer, + $$TodosTableOrderingComposer, + $$TodosTableAnnotationComposer, + $$TodosTableCreateCompanionBuilder, + $$TodosTableUpdateCompanionBuilder, + (Todo, BaseReferences<_$MyDatabase, $TodosTable, Todo>), + Todo, + PrefetchHooks Function()>; +typedef $$CategoriesTableCreateCompanionBuilder = CategoriesCompanion Function({ + Value id, + required String description, +}); +typedef $$CategoriesTableUpdateCompanionBuilder = CategoriesCompanion Function({ + Value id, + Value description, +}); + +class $$CategoriesTableFilterComposer + extends Composer<_$MyDatabase, $CategoriesTable> { + $$CategoriesTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnFilters(column)); + + ColumnFilters get description => $composableBuilder( + column: $table.description, builder: (column) => ColumnFilters(column)); +} + +class $$CategoriesTableOrderingComposer + extends Composer<_$MyDatabase, $CategoriesTable> { + $$CategoriesTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get description => $composableBuilder( + column: $table.description, builder: (column) => ColumnOrderings(column)); +} + +class $$CategoriesTableAnnotationComposer + extends Composer<_$MyDatabase, $CategoriesTable> { + $$CategoriesTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => + $composableBuilder(column: $table.id, builder: (column) => column); + + GeneratedColumn get description => $composableBuilder( + column: $table.description, builder: (column) => column); +} + +class $$CategoriesTableTableManager extends RootTableManager< + _$MyDatabase, + $CategoriesTable, + Category, + $$CategoriesTableFilterComposer, + $$CategoriesTableOrderingComposer, + $$CategoriesTableAnnotationComposer, + $$CategoriesTableCreateCompanionBuilder, + $$CategoriesTableUpdateCompanionBuilder, + (Category, BaseReferences<_$MyDatabase, $CategoriesTable, Category>), + Category, + PrefetchHooks Function()> { + $$CategoriesTableTableManager(_$MyDatabase db, $CategoriesTable table) + : super(TableManagerState( + db: db, + table: table, + createFilteringComposer: () => + $$CategoriesTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => + $$CategoriesTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$CategoriesTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: ({ + Value id = const Value.absent(), + Value description = const Value.absent(), + }) => + CategoriesCompanion( + id: id, + description: description, + ), + createCompanionCallback: ({ + Value id = const Value.absent(), + required String description, + }) => + CategoriesCompanion.insert( + id: id, + description: description, + ), + withReferenceMapper: (p0) => p0 + .map((e) => (e.readTable(table), BaseReferences(db, table, e))) + .toList(), + prefetchHooksCallback: null, + )); +} + +typedef $$CategoriesTableProcessedTableManager = ProcessedTableManager< + _$MyDatabase, + $CategoriesTable, + Category, + $$CategoriesTableFilterComposer, + $$CategoriesTableOrderingComposer, + $$CategoriesTableAnnotationComposer, + $$CategoriesTableCreateCompanionBuilder, + $$CategoriesTableUpdateCompanionBuilder, + (Category, BaseReferences<_$MyDatabase, $CategoriesTable, Category>), + Category, + PrefetchHooks Function()>; + +class $MyDatabaseManager { + final _$MyDatabase _db; + $MyDatabaseManager(this._db); + $$TodosTableTableManager get todos => + $$TodosTableTableManager(_db, _db.todos); + $$CategoriesTableTableManager get categories => + $$CategoriesTableTableManager(_db, _db.categories); +} diff --git a/examples/freezed/lib/freezed_example.freezed.dart b/examples/freezed/lib/freezed_example.freezed.dart index 7477ddf..e336d18 100644 --- a/examples/freezed/lib/freezed_example.freezed.dart +++ b/examples/freezed/lib/freezed_example.freezed.dart @@ -21,7 +21,9 @@ mixin _$UserInfoUnion { DateTime get updatedAt => throw _privateConstructorUsedError; int get primarySectionId => throw _privateConstructorUsedError; - @JsonKey(ignore: true) + /// Create a copy of UserInfoUnion + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) $UserInfoUnionCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -49,6 +51,8 @@ class _$UserInfoUnionCopyWithImpl<$Res, $Val extends UserInfoUnion> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of UserInfoUnion + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -101,6 +105,8 @@ class __$$UserInfoImplCopyWithImpl<$Res> _$UserInfoImpl _value, $Res Function(_$UserInfoImpl) _then) : super(_value, _then); + /// Create a copy of UserInfoUnion + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -172,7 +178,9 @@ class _$UserInfoImpl implements UserInfo { int get hashCode => Object.hash( runtimeType, email, loginIdentifier, updatedAt, primarySectionId); - @JsonKey(ignore: true) + /// Create a copy of UserInfoUnion + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') _$$UserInfoImplCopyWith<_$UserInfoImpl> get copyWith => @@ -194,8 +202,11 @@ abstract class UserInfo implements UserInfoUnion { DateTime get updatedAt; @override int get primarySectionId; + + /// Create a copy of UserInfoUnion + /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) _$$UserInfoImplCopyWith<_$UserInfoImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/examples/injectable/lib/getit.config.dart b/examples/injectable/lib/getit.config.dart index 9818a2f..da02943 100644 --- a/examples/injectable/lib/getit.config.dart +++ b/examples/injectable/lib/getit.config.dart @@ -8,22 +8,22 @@ // coverage:ignore-file // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:examples_injectable/mappr.dart' as _i3; -import 'package:get_it/get_it.dart' as _i1; -import 'package:injectable/injectable.dart' as _i2; +import 'package:examples_injectable/mappr.dart' as _i771; +import 'package:get_it/get_it.dart' as _i174; +import 'package:injectable/injectable.dart' as _i526; -extension GetItInjectableX on _i1.GetIt { +extension GetItInjectableX on _i174.GetIt { // initializes the registration of main-scope dependencies inside of GetIt - _i1.GetIt init({ + _i174.GetIt init({ String? environment, - _i2.EnvironmentFilter? environmentFilter, + _i526.EnvironmentFilter? environmentFilter, }) { - final gh = _i2.GetItHelper( + final gh = _i526.GetItHelper( this, environment, environmentFilter, ); - gh.lazySingleton<_i3.Mappr>(() => _i3.Mappr()); + gh.lazySingleton<_i771.Mappr>(() => _i771.Mappr()); return this; } } diff --git a/packages/auto_mappr/analysis_options.yaml b/packages/auto_mappr/analysis_options.yaml index 0b36c1f..2e9322f 100644 --- a/packages/auto_mappr/analysis_options.yaml +++ b/packages/auto_mappr/analysis_options.yaml @@ -16,7 +16,14 @@ dart_code_metrics: avoid-top-level-members-in-tests: exclude: - test/integration/fixture/** - prefer-boolean-prefixes: false # TODO: release new major version (breaking change) avoid-commented-out-code: false # code examples in comments - prefer-single-declaration-per-file: false # TODO - prefer-named-parameters: false # TODO: release new major version (breaking change) \ No newline at end of file + prefer-single-declaration-per-file: + exclude: + - test/integration/fixture/** + prefer-named-parameters: false # TODO: release new major version (breaking change) + prefer-boolean-prefixes: false # TODO: release new major version (breaking change) + # TODO: release new major version (breaking change) - uncomment lines below + # prefer-boolean-prefixes: + # exclude: + # - test/integration/fixture/** + # prefixes: ['include' , 'use', 'are', 'assign', 'with', 'will', 'maybe'] diff --git a/packages/auto_mappr/dcm_baseline.json b/packages/auto_mappr/dcm_baseline.json index 2652f08..5009a8d 100644 --- a/packages/auto_mappr/dcm_baseline.json +++ b/packages/auto_mappr/dcm_baseline.json @@ -1,5 +1,5 @@ { - "date": "2025-01-20 12:55:26.396096Z", + "date": "2025-01-21 09:08:40.977713Z", "version": "1.26.2", "paths": { "lib/src/models/type_converter.dart": { @@ -15,9 +15,7 @@ ] }, "lib/src/models/field_mapping.dart": { - "avoid-non-null-assertion": [ - "4e22d2815561f01ac60242562eb3d477" - ] + "avoid-non-null-assertion": ["4e22d2815561f01ac60242562eb3d477"] }, "lib/src/models/source_assignment.dart": { "avoid-non-null-assertion": [ @@ -26,18 +24,14 @@ "412aa7c321ce0580e16e5586de44ae45", "412aa7c321ce0580e16e5586de44ae45" ], - "avoid-nullable-interpolation": [ - "165ee04eb4d55330435a841f09c3c6b1" - ] + "avoid-nullable-interpolation": ["165ee04eb4d55330435a841f09c3c6b1"] }, "lib/src/extensions/dart_object_extension.dart": { "avoid-non-null-assertion": [ "0839d20a589c74eb461adbed71774c0c", "18cabcff3de662dfb212c548a5a39c24" ], - "avoid-nullable-interpolation": [ - "cf7dba3d85f84df468ec72f8b3744601" - ] + "avoid-nullable-interpolation": ["cf7dba3d85f84df468ec72f8b3744601"] }, "lib/src/generator/auto_mappr_generator.dart": { "avoid-non-null-assertion": [ @@ -56,9 +50,7 @@ ] }, "lib/src/builder/methods/private_convert_method_builder.dart": { - "avoid-non-null-assertion": [ - "a8022779055b7c4c7bf23042d14e613a" - ] + "avoid-non-null-assertion": ["a8022779055b7c4c7bf23042d14e613a"] }, "lib/src/builder/assignments/record_assignment_builder.dart": { "avoid-non-null-assertion": [ @@ -122,9 +114,7 @@ ] }, "lib/src/builder/map_bodies/enum_body_builder.dart": { - "avoid-non-null-assertion": [ - "a8022779055b7c4c7bf23042d14e613a" - ] + "avoid-non-null-assertion": ["a8022779055b7c4c7bf23042d14e613a"] } } } \ No newline at end of file diff --git a/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart index 4becadb..c794173 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart @@ -24,8 +24,8 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM final sourceType = assignment.sourceType!; final targetType = assignment.targetType; - final sourceNullable = sourceType.isNullable; - final targetNullable = targetType.isNullable; + final isSourceNullable = sourceType.isNullable; + final isTargetNullable = targetType.isNullable; final sourceIterableType = sourceType.genericParameterTypeOrSelf; final targetIterableType = targetType.genericParameterTypeOrSelf; @@ -38,7 +38,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM // When [sourceIterableType] is nullable and [targetIterableType] is not, remove null values. final sourceIterableExpression = AssignmentBuilderBase.modelReference.property(assignment.sourceField!.name).maybeWhereIterableNotNull( condition: shouldFilterNullInSource, - isOnNullable: sourceNullable, + isOnNullable: isSourceNullable, ); final defaultIterableValueExpression = targetType.defaultIterableExpression(); @@ -46,7 +46,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM if (assignNestedObject) { return sourceIterableExpression // Map complex nested types. - .maybeNullSafeProperty('map', isOnNullable: sourceNullable) + .maybeNullSafeProperty('map', isOnNullable: isSourceNullable) .call( [_map(assignment)], {}, @@ -61,7 +61,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM isOnNullable: false, ) // When [sourceNullable], use default value. - .maybeIfNullThen(defaultIterableValueExpression, isOnNullable: sourceNullable && !targetNullable); + .maybeIfNullThen(defaultIterableValueExpression, isOnNullable: isSourceNullable && !isTargetNullable); } return sourceIterableExpression @@ -69,11 +69,11 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM source: sourceType, target: targetType, forceCast: shouldFilterNullInSource, // if whereNotNull was used -> we want to force toIterable() call - isOnNullable: !targetNullable && sourceNullable, + isOnNullable: !isTargetNullable && isSourceNullable, ) .maybeIfNullThen( defaultIterableValueExpression, - isOnNullable: !targetNullable && sourceNullable, + isOnNullable: !isTargetNullable && isSourceNullable, ); } diff --git a/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart index a9d0338..71320f8 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart @@ -27,8 +27,8 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final sourceType = assignment.sourceType!; final targetType = assignment.targetType; - final sourceNullable = sourceType.isNullable; - final targetNullable = targetType.isNullable; + final isSourceNullable = sourceType.isNullable; + final isTargetNullable = targetType.isNullable; final sourceKeyType = (sourceType as ParameterizedType).typeArguments.firstOrNull; final sourceValueType = sourceType.typeArguments.lastOrNull; @@ -36,10 +36,10 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final targetKeyType = (targetType as ParameterizedType).typeArguments.firstOrNull; final targetValueType = targetType.typeArguments.lastOrNull; - final sourceNullableKey = sourceKeyType?.isNullable ?? false; - final sourceNullableValue = sourceValueType?.isNullable ?? false; - final targetNullableKey = targetKeyType?.isNullable ?? false; - final targetNullableValue = targetValueType?.isNullable ?? false; + final isSourceNullableKey = sourceKeyType?.isNullable ?? false; + final isSourceNullableValue = sourceValueType?.isNullable ?? false; + final isTargetNullableKey = targetKeyType?.isNullable ?? false; + final isTargetNullableValue = targetValueType?.isNullable ?? false; if (targetKeyType == null || targetValueType == null) { final emittedTarget = EmitterHelper.current.typeReferEmitted(type: targetType); @@ -62,11 +62,11 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin // Keys: source is null, target is not null, and default value does not exist. final shouldRemoveNullsKey = - sourceNullableKey && !targetNullableKey && (!(keyMapping?.hasWhenNullDefault() ?? false)); + isSourceNullableKey && !isTargetNullableKey && (!(keyMapping?.hasWhenNullDefault() ?? false)); // Value: source is null, target is not null, and default value does not exist. final shouldRemoveNullsValue = - sourceNullableValue && !targetNullableValue && (!(valueMapping?.hasWhenNullDefault() ?? false)); + isSourceNullableValue && !isTargetNullableValue && (!(valueMapping?.hasWhenNullDefault() ?? false)); final sourceMapExpression = AssignmentBuilderBase.modelReference.property(assignment.sourceField!.name); @@ -84,7 +84,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin return sourceMapExpression // Filter nulls when source key/value is nullable and target is not. .maybeWhereMapNotNull( - isOnNullable: sourceNullable, + isOnNullable: isSourceNullable, keyIsNullable: shouldRemoveNullsKey, valueIsNullable: shouldRemoveNullsValue, keyType: sourceKeyType, @@ -92,7 +92,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin ) .maybeCall( 'map', - isOnNullable: sourceNullable, + isOnNullable: isSourceNullable, // Call map only when actually some mapping is required. condition: shouldDoMapCall, positionalArguments: [_map(assignment)], @@ -102,7 +102,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin ], ) // When [sourceNullable], use default value. - .maybeIfNullThen(defaultMapValueExpression, isOnNullable: sourceNullable && !targetNullable); + .maybeIfNullThen(defaultMapValueExpression, isOnNullable: isSourceNullable && !isTargetNullable); } Expression _map(SourceAssignment assignment) { @@ -128,8 +128,8 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final assignNestedObjectKey = !targetKeyType.isPrimitiveType && (targetKeyType != sourceKeyType); final assignNestedObjectValue = !targetValueType.isPrimitiveType && (targetValueType != sourceValueType); - final keysAreSameType = sourceKeyType == targetKeyType; - final valuesAreSameType = sourceValueType == targetValueType; + final areKeysSameType = sourceKeyType == targetKeyType; + final areValuesSameType = sourceValueType == targetValueType; // Returns a tear off when no nested call is needed. if (!assignNestedObjectKey && !assignNestedObjectValue) { @@ -144,7 +144,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin assignment: assignment, source: sourceKeyType, target: targetKeyType, - convertMethodArgument: keysAreSameType ? null : sourceMapExpression, + convertMethodArgument: areKeysSameType ? null : sourceMapExpression, ) : sourceMapExpression; @@ -153,7 +153,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin assignment: assignment, source: sourceValueType, target: targetValueType, - convertMethodArgument: valuesAreSameType ? null : targetMapExpression, + convertMethodArgument: areValuesSameType ? null : targetMapExpression, ) : targetMapExpression; diff --git a/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart b/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart index 0cdd008..aa12c66 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart @@ -120,9 +120,9 @@ mixin NestedObjectMixin on AssignmentBuilderBase { Expression? convertMethodArgument, bool includeGenericTypes = false, }) { - final targetNullable = target.isNullable; + final isTargetNullable = target.isNullable; - final useNullableMethod = targetNullable && !mapping.hasWhenNullDefault(); + final useNullableMethod = isTargetNullable && !mapping.hasWhenNullDefault(); // When target is nullable, use nullable convert method. // But use non-nullable when the mapping has default value. diff --git a/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart index 3d033cf..cf62bd4 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart @@ -97,8 +97,8 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix }) { if (source == null) return literalNull; - final valuesAreSameType = source.type == target.type; - final shouldAssignNestedObject = !target.type.isPrimitiveType && !valuesAreSameType; + final areValuesSameType = source.type == target.type; + final shouldAssignNestedObject = !target.type.isPrimitiveType && !areValuesSameType; final targetRecordExpression = refer(assignment.sourceField!.name); @@ -110,7 +110,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix assignment: assignment, source: source.type, target: target.type, - convertMethodArgument: valuesAreSameType ? null : targetRecordExpression, + convertMethodArgument: areValuesSameType ? null : targetRecordExpression, ); return refer('${valueExpression.accept(EmitterHelper.current.emitter)})'); @@ -130,8 +130,8 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix }) { if (source == null) return literalNull; - final valuesAreSameType = source.type == target.type; - final shouldAssignNestedObject = !target.type.isPrimitiveType && !valuesAreSameType; + final areValuesSameType = source.type == target.type; + final shouldAssignNestedObject = !target.type.isPrimitiveType && !areValuesSameType; final targetRecordExpression = refer(assignment.sourceField!.name); @@ -143,7 +143,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix assignment: assignment, source: source.type, target: target.type, - convertMethodArgument: valuesAreSameType ? null : targetRecordExpression, + convertMethodArgument: areValuesSameType ? null : targetRecordExpression, ); return refer('${valueExpression.accept(EmitterHelper.current.emitter)})'); diff --git a/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart b/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart index b045698..8ab4d1e 100644 --- a/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart +++ b/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart @@ -32,9 +32,9 @@ class EnumBodyBuilder extends MapBodyBuilderBase { final sourceValues = sourceEnum.fields.where((e) => e.isEnumConstant && e.isPublic).map((e) => e.name).toSet(); final targetValues = targetEnum.fields.where((e) => e.isEnumConstant && e.isPublic).map((e) => e.name).toSet(); - final sourceIsSubset = targetValues.containsAll(sourceValues); + final isSourceSubset = targetValues.containsAll(sourceValues); - if (!sourceIsSubset && !mapping.hasWhenNullDefault()) { + if (!isSourceSubset && !mapping.hasWhenNullDefault()) { final sourceDisplay = mapping.source.getDisplayString(); final targetDisplay = mapping.target.getDisplayString(); throw InvalidGenerationSourceError( diff --git a/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart index 030d7fb..013d871 100644 --- a/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart @@ -102,8 +102,8 @@ class ValueAssignmentBuilder { return rightSide.ifNullThen(fieldMapping!.whenNullExpression!); } - final sourceNullable = assignment.sourceType!.isNullable; - final targetNullable = assignment.targetType.isNullable; + final isSourceNullable = assignment.sourceType!.isNullable; + final isTargetNullable = assignment.targetType.isNullable; // BANG operator when Source is nullable and Target not final shouldIgnoreNull = fieldMapping?.ignoreNull ?? @@ -111,7 +111,7 @@ class ValueAssignmentBuilder { mapperConfig.mapprOptions.ignoreNullableSourceField ?? false; - if (shouldIgnoreNull && sourceNullable && !targetNullable) { + if (shouldIgnoreNull && isSourceNullable && !isTargetNullable) { return refer(sourceField.isStatic ? '${sourceField.enclosingElement.name}' : 'model') .property(sourceField.name) .nullChecked; diff --git a/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart b/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart index e0f6863..47ee29c 100644 --- a/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart +++ b/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart @@ -136,9 +136,9 @@ class AutoMapprGenerator extends GeneratorForAnnotation { final mapTypeConverters = mapper.getField(mapTypeFieldConverters)?.toListValue() ?? []; final whenSourceIsNull = mapper.getField(mapTypeFieldWhenSourceIsNull)?.toCodeExpression(); final constructor = mapper.getField(mapTypeFieldConstructor)?.toStringValue(); - final ignoreFieldNull = mapper.getField(mapTypeFieldIgnoreFieldNull)?.toBoolValue(); - final reverse = mapper.getField(mapTypeFieldReverse)?.toBoolValue(); - final safeMapping = mapper.getField(mapTypeSafeMapping)?.toBoolValue(); + final willIgnoreFieldNull = mapper.getField(mapTypeFieldIgnoreFieldNull)?.toBoolValue(); + final isReverse = mapper.getField(mapTypeFieldReverse)?.toBoolValue(); + final hasSafeMapping = mapper.getField(mapTypeSafeMapping)?.toBoolValue(); final fieldMappings = fields ?.map( @@ -162,10 +162,10 @@ class AutoMapprGenerator extends GeneratorForAnnotation { typeConverters: [..._toTypeConverters(mapTypeConverters), ...globalConverters], whenSourceIsNullExpression: whenSourceIsNull, constructor: constructor, - ignoreFieldNull: ignoreFieldNull, - safeMapping: safeMapping, + ignoreFieldNull: willIgnoreFieldNull, + safeMapping: hasSafeMapping, ), - if (reverse ?? false) + if (isReverse ?? false) TypeMapping( source: targetType, target: sourceType, @@ -187,8 +187,8 @@ class AutoMapprGenerator extends GeneratorForAnnotation { typeConverters: [..._toTypeConverters(mapTypeConverters), ...globalConverters], whenSourceIsNullExpression: whenSourceIsNull, constructor: constructor, - ignoreFieldNull: ignoreFieldNull, - safeMapping: safeMapping, + ignoreFieldNull: willIgnoreFieldNull, + safeMapping: hasSafeMapping, ), ]; }) diff --git a/packages/auto_mappr/lib/src/models/source_assignment.dart b/packages/auto_mappr/lib/src/models/source_assignment.dart index be9447f..5f41969 100644 --- a/packages/auto_mappr/lib/src/models/source_assignment.dart +++ b/packages/auto_mappr/lib/src/models/source_assignment.dart @@ -1,4 +1,5 @@ //ignore_for_file: prefer-match-file-name +// ignore_for_file: prefer-single-declaration-per-file import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart';