Init
Creates a JSON file with all existing rule violations which will be used by IDE integrations and CLI as baseline. All violations in this file won't be reported unless the related code is changed. To execute the command, run:
$ dcm init lib # or dcm i lib
Each analysis_options file will have its own baseline file generated.
You need to configure rules
entry in the analysis_options.yaml
to have rule violations included into the baseline file.
Full command description:
Usage: dcm init [arguments] <directories>
-h, --help Print this usage information.
-c, --print-config Print resolved config.
--root-folder=<./> Root folder.
(defaults to current directory)
--sdk-path=<directory-path> Dart SDK directory path.
If the project has a `.fvm/flutter_sdk` symlink, it will be used if the SDK is not found.
--exclude=<{/**.g.dart,/**.freezed.dart}> File paths in Glob syntax to be exclude.
(defaults to "{/**.g.dart,/**.freezed.dart}")
--no-congratulate Don't show output even when there are no issues.
--[no-]verbose Show verbose logs.
--ci-key The license key to run on CI server.
--email The email used to purchase the license.
--no-analytics Disable sending anonymous usage statistics.
Output example
The file with the baseline should be added to the version control system (ex. git).
{
"date": "2023-04-06 11:21:12.433111Z",
"paths": {
"lib/src/fixes/models/fix_producer.dart": {
"prefer-match-file-name": [
"2dca28e191c53faa330a518d0af4ffc5"
]
},
"lib/src/fixes/correct_source_visitor.dart": {
"no-empty-block": [
"99914b932bd37a50b983c5e7c90ae93b",
"99914b932bd37a50b983c5e7c90ae93b"
],
"prefer-correct-identifier-length": [
"865c0c0b4ab0e063e5caa3387c1a8741",
"865c0c0b4ab0e063e5caa3387c1a8741"
]
},
"lib/src/analyzers/unused_code_analyzer/public_code_visitor.dart": {
"avoid-collapsible-if": [
"271a669d554d76db67710f0c8f9fc94e"
]
},
"lib/src/analyzers/lint_analyzer/models/pubspec.dart": {
"prefer-declaring-const-constructor": [
"1945e177acd751da03bd522e62e2c311",
"670d86c2a7346221f669991d369c4360",
"fadb753cbdce4b42d9aac6d229db1302",
"de155dd175502bdf44e6f783fafa29a8",
"70db9b0ff6a2d5431196b767091ffab8",
"a5ee9c6c05983f0fd2fbf9e0f5fe58a0",
"747e2f2f1c4c05cb7e05d7336a468b9e",
"b09149af1d532f3f84ef7f12bf3a6dd7",
"734cb7aedc290a4ef4211fe745f86a1c",
"7907bf00d43aad3bf9fb1ebad2e192dc",
"e797dcde58afe1c9a72cfa52f5021ea0"
],
"prefer-correct-identifier-length": [
"26148d621ef74844918af182d63976b6"
]
},
"lib/src/analyzers/lint_analyzer/rules/avoid_returning_widgets/visit_declaration.dart": {
"prefer-match-file-name": [
"079e73eb013b9d4fc05af9c17f673205"
]
},
"lib/src/analyzers/metrics_analyzer/metrics/tight_class_cohesion/tight_class_cohesion_metric.dart": {
"prefer-correct-identifier-length": [
"865c0c0b4ab0e063e5caa3387c1a8741",
"363b122c528f54df4a0446b6bab05515"
]
},
"lib/src/analyzers/metrics_analyzer/models/calculated_metric.dart": {
"prefer-match-file-name": [
"ab3538804524170f077b69400f2e5be3"
]
}
}
}
The baseline contains all file paths that have violations which are grouped by a rule name for easy gradual fixes. If you want to fix violations in a certain file, you can simply remove that file's entry from the baseline and the violations will appear.
The IDE must be restarted each time the baseline file is changed for the changes to take effect.