Skip to main content
Teams

Init

General command to set up DCM. Supports two subcommands: "baseline" and "preview".

Full command description:

Usage: dcm init <subcommand> [arguments] <directories>
-h, --help Print this usage information.

Available subcommands:
baseline Generate baseline.
preview Preview number of issues generated by lint rules.

Baseline

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.

note

Each analysis_options file will have its own baseline file generated. The baseline file won't be generated if the analysis produces no issues.

info

You need to configure rules entry in the analysis_options.yaml to have rule violations included into the baseline file.

To execute the command, run:

$ dcm init baseline lib # or dcm i b lib

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 the 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.


--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.

IDE integrations

When your project has a generated baseline file, the code actions menu in the IDE will show an additional action to include issues from the current file to the baseline. When issues are included to the baseline via a code action, no analysis server restart is needed for this update to take effect.

Monorepo support

For repositories with multiple packages, calling dcm init baseline . from the root of the repository will create a baseline file for each analysis_options.yaml.

If several packages share the same analysis_options.yaml, the baseline file will contain issues from all those packages.

info

Calling dcm init baseline . inside a package that shares analysis_options.yaml with other package will make the baseline to contain issues only from that particular package.

Line endings

Line endings in your files can affect the baseline output. Make sure you only have one type of line endings configured.

You can configure line endings via .editorconfig and .gitattributes.

Case sensitivity

Some platforms (such as macOS) are case-insensitive, which can result in differences in local and remote (e.g. in your git repo) file names.

If the baseline does not work on CI/CD for a particular file, make sure there is no case difference.

Output example

warning

The file with the baseline should be added to the version control system (ex. git).

dcm_baseline.json
{
"date": "2023-04-06 11:21:12.433111Z",
"version": "1.16.0",
"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.

warning

The IDE must be restarted each time the baseline file is changed for the changes to take effect.

Preview

Runs selected (by default all available) rules against the given directories and shows the number of issues generated by each rule.

note

Enabled rules are always included into the set of selected rules.

info

This command supports different output formats. See "Output Example" for more details.

To execute the command, run:

$ dcm init preview lib # or dcm i p lib

Full command description:

Usage: dcm init preview [arguments] <directories>
-h, --help Print this usage information.


--format=<console> Output format.
[console (default), table, analysis_options]
--severity=<warning> Report rules only with this severity.
[error (default), warning (default), perf (default), style (default), none (default)]
--rule-types=<flutter> Rule types to include.
[common (default), flutter (default), intl (default), flame (default), provider (default), bloc (default), equatable (default), patrol (default)]
--only-fixable Show only fixable violations.
--no-empty-violations Hide rules with 0 violations.
--no-baseline-violations Hide violations included into baseline.

--root-folder=<./> Root folder.
(defaults to the current directory)
--sdk-path=<directory-path> Dart SDK directory path.
--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.


--ci-key The license key to run on CI server. Can be provided via DCM_CI_KEY env variable.
--email The email used to purchase the license. Can be provided via DCM_EMAIL env variable.


--no-analytics Disable sending anonymous usage statistics.

Configuring the set of rules

By default, the command runs all available rules.

You can change this behavior by passing --severity, --rule-types and --only-fixable options.

For example, to get only for Flutter and Bloc rule violations with warning and style severities, pass --severity=warning,style --rule-types=flutter,bloc.

info

Pass --no-empty-violations if you want to excluded rules with 0 violations from the output.

Output example

Console (default)

Console example

Table

Use --format=table to enable this format.

Table example

Analysis Options

Use --format=analysis_options to enable this format.

Analysis Options example