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.

Any violations added to this file will not be reported until 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)
-s, --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.
-e, --exclude=<{**/*.g.dart,**/*.freezed.dart}> File paths in Glob syntax to be exclude.
(defaults to "{**/*.g.dart,**/*.freezed.dart}")


--[no-]congratulate 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 result in the baseline containing issues only from that specific 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 (e.g. 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"
]
}
}
}

The baseline contains all the file paths that have violations, grouped by rule name for easy incremental fixing. If you want to fix violations in a specific 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.

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.
[analysis_options, console (default), table]
--severity=<all> Report rules only with this severity (all by default).
[error (default), warning (default), style (default), none (default)]
--rule-types=<all> Rule categories to include (all by default).
[common (default), flutter (default), intl (default), flame (default), fake-async (default), provider (default), bloc (default), equatable (default), patrol (default), get-it (default), flutter-hooks (default), riverpod (default), getx (default), easy-localization (default), firebase-analytics (default)]
--rule-version=<all> Rule version to include (all by default).
[1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0, 1.7.0, 1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0, 1.13.0, 1.14.0, 1.15.0, 1.16.0, 1.17.0, 1.18.0, 1.19.0, 1.20.0, 1.21.0, 1.22.0, 1.23.0, 1.24.0, 1.25.0]
--rule-tags=<all> Rule tags to include (all by default).
[accessibility, architecture, consistency, requires-config, unused-code, pedantic, performance, memory-leak, correctness, readability, maintainability, security, cwe]
--only-enabled Include only enabled rules.
--only-absent Include only those rules that are not added to the configuration.
--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)
-s, --sdk-path=<directory-path> Dart SDK directory path.
-e, --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, --rule-version, --rule-tags, --only-absent, --only-enabled and --only-fixable options.

For example, to get rule violations only for Flutter and Bloc, and 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.

Understanding the Estimated Effort

This command also shows the estimated effort to fix all violations of a particular rule (the value can be in minutes or in hours).

Rules that are supported by "dcm fix" have a lower estimated effort as they only require a review after the fixes are applied.

note

This number is very approximate and is shown only to help you decide which violations to address first.

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