Skip to content

Commit

Permalink
chore: improve dcm, create baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
mathew65 committed Jan 20, 2025
1 parent 457b067 commit d50ec30
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 26 deletions.
7 changes: 2 additions & 5 deletions packages/auto_mappr/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ dart_code_metrics:
avoid-top-level-members-in-tests:
exclude:
- test/integration/fixture/**
avoid-non-null-assertion: false # TODO
avoid-nullable-interpolation: false # TODO
prefer-boolean-prefixes: false # TODO
avoid-passing-default-values: false # TODO
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
prefer-named-parameters: false # TODO: release new major version (breaking change)
130 changes: 130 additions & 0 deletions packages/auto_mappr/dcm_baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"date": "2025-01-20 12:55:26.396096Z",
"version": "1.26.2",
"paths": {
"lib/src/models/type_converter.dart": {
"avoid-non-null-assertion": [
"49d6910256d6a9925f1f305647170175",
"3e2fb62702f0d6d976c0ef4838e256f3",
"37d7521d3b9436994de3d46bfec19156",
"37d560854197d3d451fa40ebda978adf",
"6002ec186df142e2eeabc594fb05b0cd",
"32d05f2391dfd5a054110f0cf5b00edb",
"2bde3d2541dbd52f427522d8859dddbc",
"4901e165d9d77551c2b961387d8f709b"
]
},
"lib/src/models/field_mapping.dart": {
"avoid-non-null-assertion": [
"4e22d2815561f01ac60242562eb3d477"
]
},
"lib/src/models/source_assignment.dart": {
"avoid-non-null-assertion": [
"8f0912f968e86ab46d0dd647c5d322e9",
"8f0912f968e86ab46d0dd647c5d322e9",
"412aa7c321ce0580e16e5586de44ae45",
"412aa7c321ce0580e16e5586de44ae45"
],
"avoid-nullable-interpolation": [
"165ee04eb4d55330435a841f09c3c6b1"
]
},
"lib/src/extensions/dart_object_extension.dart": {
"avoid-non-null-assertion": [
"0839d20a589c74eb461adbed71774c0c",
"18cabcff3de662dfb212c548a5a39c24"
],
"avoid-nullable-interpolation": [
"cf7dba3d85f84df468ec72f8b3744601"
]
},
"lib/src/generator/auto_mappr_generator.dart": {
"avoid-non-null-assertion": [
"7a50c2efb20fe138dc37e6550e009160",
"b877c976f457e163c51a7c84f5777069",
"695248e6e85f1fecba6bf6c344ea8187",
"9825f25ed373f63c6d3efc8caffaaef1",
"25851cd74f03edbac9719dacc76c4bcc",
"acd1213c9abd408fac46b00b6631d6a2",
"43019f988cd8e5f2b155f1375dc99da2",
"05fe4fffcb9159fd5c0dd62f0e6fb7c5",
"bc359bcc3ec98cd8aada89ff9b0046e9",
"f3c3ceea53e478439edd662d2793cf00",
"ac37c4c51b2a4b1187b271e1f71cde2e",
"48e33839a8de547d03f16d3b4f023b1e"
]
},
"lib/src/builder/methods/private_convert_method_builder.dart": {
"avoid-non-null-assertion": [
"a8022779055b7c4c7bf23042d14e613a"
]
},
"lib/src/builder/assignments/record_assignment_builder.dart": {
"avoid-non-null-assertion": [
"0bd202edba38880d347468eaa934da83",
"3cb7b9402c27519c759bb527c0bf7693",
"3cb7b9402c27519c759bb527c0bf7693"
]
},
"lib/src/builder/assignments/map_assignment_builder.dart": {
"avoid-non-null-assertion": [
"0bd202edba38880d347468eaa934da83",
"3cb7b9402c27519c759bb527c0bf7693",
"0bd202edba38880d347468eaa934da83",
"0bd202edba38880d347468eaa934da83"
]
},
"lib/src/builder/assignments/iterable_assignment_builder.dart": {
"avoid-non-null-assertion": [
"0bd202edba38880d347468eaa934da83",
"3cb7b9402c27519c759bb527c0bf7693",
"0bd202edba38880d347468eaa934da83"
]
},
"lib/src/builder/assignments/nested_object_mixin.dart": {
"avoid-non-null-assertion": [
"3cb7b9402c27519c759bb527c0bf7693",
"02b8861952b1d31c7e3fc701a1196ef3",
"1e8062cd91c977990ce8a7e9808b7a30"
],
"avoid-nullable-interpolation": [
"48d7effa328cb38d0a736b2496a897b0",
"20d7c588ba9f39a442116c71149ea3b8"
]
},
"lib/src/builder/map_model_body_method_builder.dart": {
"avoid-non-null-assertion": [
"a8022779055b7c4c7bf23042d14e613a",
"a8022779055b7c4c7bf23042d14e613a"
]
},
"lib/src/builder/value_assignment_builder.dart": {
"avoid-non-null-assertion": [
"da5b0598f70c2b82fb9db2510920be2c",
"0bd202edba38880d347468eaa934da83",
"0bd202edba38880d347468eaa934da83",
"02b8861952b1d31c7e3fc701a1196ef3",
"1e8062cd91c977990ce8a7e9808b7a30",
"0bd202edba38880d347468eaa934da83"
],
"avoid-nullable-interpolation": [
"019cf3c46b0e37f0339187e7f06d9984",
"019cf3c46b0e37f0339187e7f06d9984"
]
},
"lib/src/builder/map_bodies/class_body_builder.dart": {
"avoid-non-null-assertion": [
"374cdacb7c32728a88ad32f9ec5821ff",
"dfda47d1f6044e6fcb565ff03e9721e3",
"927919a5768cf07ec40df0aca3c14e73",
"24f4441455b612dc6d0d29bf53d82f03"
]
},
"lib/src/builder/map_bodies/enum_body_builder.dart": {
"avoid-non-null-assertion": [
"a8022779055b7c4c7bf23042d14e613a"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
}

void _assertParamFieldCanBeIgnored(ParameterElement param, PropertyAccessorElement sourceField) {
final sourceFieldName = sourceField.getDisplayString(withNullability: true);
final sourceFieldName = sourceField.getDisplayString();
if (param.isPositional && param.type.isNotNullable) {
throw InvalidGenerationSourceError(
"Can't ignore field '$sourceFieldName' as it is positional not-nullable parameter. ($mapping)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class EnumBodyBuilder extends MapBodyBuilderBase {

// Check that both source and target enums are enums.
if (!isSourceEnum || !isTargetEnum) {
final sourceDisplay = mapping.source.getDisplayString(withNullability: true);
final targetDisplay = mapping.target.getDisplayString(withNullability: true);
final sourceDisplay = mapping.source.getDisplayString();
final targetDisplay = mapping.target.getDisplayString();

throw InvalidGenerationSourceError(
'Failed to map $mapping because ${isSourceEnum ? 'target $targetDisplay' : 'source $sourceDisplay'} is not an enum.',
Expand All @@ -35,8 +35,8 @@ class EnumBodyBuilder extends MapBodyBuilderBase {
final sourceIsSubset = targetValues.containsAll(sourceValues);

if (!sourceIsSubset && !mapping.hasWhenNullDefault()) {
final sourceDisplay = mapping.source.getDisplayString(withNullability: true);
final targetDisplay = mapping.target.getDisplayString(withNullability: true);
final sourceDisplay = mapping.source.getDisplayString();
final targetDisplay = mapping.target.getDisplayString();
throw InvalidGenerationSourceError(
"Can't map enum $sourceDisplay into $targetDisplay. Target enum is not superset of source enum. ($mapping)",
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//ignore_for_file: avoid-dynamic

import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
Expand Down Expand Up @@ -193,7 +192,7 @@ class AutoMapprGenerator extends GeneratorForAnnotation<annotation.AutoMappr> {
),
];
})
// ignore: avoid-slow-collection-methods, fix dcm without refactoring
// ignore: avoid-slow-collection-methods, it's ok to use here
.flattened
.toList();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auto_mappr/lib/src/models/auto_mappr_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class AutoMapprConfig {
String _getTypeMappingDocs(TypeMapping typeMapping) {
final trailingPart = typeMapping.hasWhenNullDefault() ? ' -- With default value.' : '.';
// Display without import aliases.
final emittedSource = typeMapping.source.getDisplayString(withNullability: true);
final emittedTarget = typeMapping.target.getDisplayString(withNullability: true);
final emittedSource = typeMapping.source.getDisplayString();
final emittedTarget = typeMapping.target.getDisplayString();

// ignore: avoid-non-ascii-symbols, it is ok
return '/// - `$emittedSource` → `$emittedTarget`$trailingPart';
Expand Down
4 changes: 2 additions & 2 deletions packages/auto_mappr/lib/src/models/type_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class TypeConverter extends Equatable {

@override
String toString() {
final sourceX = source.getDisplayString(withNullability: true);
final targetX = target.getDisplayString(withNullability: true);
final sourceX = source.getDisplayString();
final targetX = target.getDisplayString();

return 'typeConverter $sourceX -> $targetX';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auto_mappr/lib/src/models/type_mapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class TypeMapping extends Equatable {
@override
String toString() {
// Without import aliases, used to display errors to user.
final sourceAsString = source.getDisplayString(withNullability: true);
final targetAsString = target.getDisplayString(withNullability: true);
final sourceAsString = source.getDisplayString();
final targetAsString = target.getDisplayString();

// ignore: avoid-non-ascii-symbols, it is ok
return '$sourceAsString → $targetAsString';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class Mappr extends $Mappr {

static Map<String, int> emptyToMapValue(CustomFunctionFromEmptyDto? _) => {'one': 11, 'two': 22, 'three': 33};

static String convertToNameAndIdPositional(CustomFunctionPositionalDto? dto) => '${dto?.name} #${dto?.id}';
static String convertToNameAndIdPositional(CustomFunctionPositionalDto dto) => '${dto.name} #${dto.id}';

static String convertToNameAndIdNamed(CustomFunctionNamedDto? dto) => '${dto?.name} #${dto?.id}';
static String convertToNameAndIdNamed(CustomFunctionNamedDto dto) => '${dto.name} #${dto.id}';

static DateTime dateTimeFixed() => DateTime(2023);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auto_mappr/test/integration/fixture/rename.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import 'rename.auto_mappr.dart';
),
])
class Mappr extends $Mappr {
static String convertToNameAndIdPositional(CustomPositionalDto? dto) => '${dto?.name} #${dto?.id}';
static String convertToNameAndIdPositional(CustomPositionalDto dto) => '${dto.name} #${dto.id}';

static String convertToNameAndIdNamed(CustomNamedDto? dto) => '${dto?.name} #${dto?.id}';
static String convertToNameAndIdNamed(CustomNamedDto dto) => '${dto.name} #${dto.id}';
}

// same
Expand Down
3 changes: 0 additions & 3 deletions packages/auto_mappr_annotation/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ dart_code_metrics:
- package:netglade_analysis/dcm.yaml
pubspec-rules:
prefer-publish-to-none: false
rules:
prefer-boolean-prefixes: false # TODO
prefer-named-parameters: false # TODO
28 changes: 28 additions & 0 deletions packages/auto_mappr_annotation/dcm_baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"date": "2025-01-20 11:07:26.586363Z",
"version": "1.26.2",
"paths": {
"lib/src/auto_mappr_interface.dart": {
"prefer-boolean-prefixes": [
"f8e45531a3ea3d5c1247b004985175a4",
"9696113cbf65a7d0a20c3b28984795f6"
],
"prefer-named-parameters": [
"d2eb52ce2ae9079bc52e9a13a6a44c1e"
]
},
"lib/src/map_type.dart": {
"prefer-boolean-prefixes": [
"2d42e74f6260722660851c540faa9b08",
"4d9c2073afa3c2abb817dceb22c34de6",
"cdf1cce8a80c3ed282b32d792e2d6a76"
]
},
"lib/src/field.dart": {
"prefer-boolean-prefixes": [
"567bc1d268f135496de3d5b946b691f3",
"1d93a811b1cf660fbae038a0f6ea19cb"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/auto_mappr_annotation/lib/src/map_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:auto_mappr_annotation/src/field.dart';
import 'package:auto_mappr_annotation/src/type_converter.dart';

/// Configured mapping from [SOURCE] to [TARGET].
// ignore: avoid-unused-generics, dcm fix without refactoring
// ignore: avoid-unused-generics, generic are used later in code
final class MapType<SOURCE, TARGET> {
/// Configuration for [TARGET]'s fields.
final List<Field> fields;
Expand Down

0 comments on commit d50ec30

Please sign in to comment.