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.
Each analysis_options file will have its own baseline file generated. The baseline file won't be generated if the analysis produces no issues.
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 baseline [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}" Files to exclude (in Glob syntax).
(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. 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.
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.
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​
The file with the baseline should be added to the version control system (e.g. git).
{
"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.
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.
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) Format as plain text.
[analysis_options] Format as analysis_options.yaml.
[table] Format as table.
--severity="warning,style,..." Report rules only with this severity (all by default).
[error] (default) Rules with the 'error' severity.
[warning] (default) Rules with the 'warning' severity.
[style] (default) Rules with the 'style' severity.
[none] (default) Rules with the 'none' severity.
--rule-types="common,flutter,..." Rule categories to include (all by default).
[common] (default) Rules for Dart.
[flutter] (default) Rules for Flutter.
[intl] (default) Rules for the 'intl' package.
[flame] (default) Rules for the 'flame' package.
[fake-async] (default) Rules for the 'fake_async' package.
[provider] (default) Rules for the 'provider' package.
[bloc] (default) Rules for the 'bloc' package.
[equatable] (default) Rules for the 'equatable' package.
[patrol] (default) Rules for the 'patrol' package.
[get-it] (default) Rules for the 'get_it' package.
[flutter-hooks] (default) Rules for the 'flutter_hooks' package.
[riverpod] (default) Rules for the 'riverpod' package.
[getx] (default) Rules for the 'getx' package.
[easy-localization] (default) Rules for the 'easy_localization' package.
[firebase-analytics] (default) Rules for the 'firebase_analytics' package.
--rule-version="1.26.0" Rule version to include (all by default).
[1.0.0] Rules added in 1.0.0
[1.1.0] Rules added in 1.1.0
[1.2.0] Rules added in 1.2.0
[1.3.0] Rules added in 1.3.0
[...]
[1.23.0] Rules added in 1.23.0
[1.24.0] Rules added in 1.24.0
[1.25.0] Rules added in 1.25.0
[1.26.0] Rules added in 1.26.0
--rule-tags="correctness,consistency,..." Rule tags to include (all by default).
[abstractions] Rules for detecting abstraction issues.
[accessibility] Rules for detecting accessibility issues.
[architecture] Rules for enforcing architecture agreements.
[assignments] Rules for detecting issues with assignments.
[async] Rules for detecting issues with asynchronous code and Futures.
[collections] Rules for detecting issues with collections.
[conditions] Rules for detecting issues with conditions and logical expressions.
[consistency] Rules for detecting consistency issues.
[control-flow] Rules for detecting control flow issues.
[correctness] Rules for detecting potential bugs.
[cwe] Rules for detecting CWE issues.
[encapsulation] Rules for detecting issues with encapsulation.
[error-handling] Rules for detecting issues with exceptions and error handling.
[imports] Rules for detecting issues with imports and exports.
[maintainability] Rules for improving maintainability.
[memory-leak] Rules for detecting memory leaks.
[naming] Rules for detecting naming issues.
[nullability] Rules for detecting nullability issues.
[pedantic] Rules for pedantic devs!
[performance] Rules for detecting performance issues.
[readability] Rules for improving readability.
[requires-config] Rules that require configuration.
[security] Rules for detecting security issues.
[testing] Rules for detecting issues with tests.
[types] Rules for detecting issues with type operations and annotations.
[unused-code] Rules for detecting unused code.
--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}" Files to exclude (in Glob syntax).
(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
.
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.
This number is very approximate and is shown only to help you decide which violations to address first.
Output Example​
Console (default)​
Table​
Use --format=table
to enable this format.
Analysis Options​
Use --format=analysis_options
to enable this format.