Configuration
DCM is designed to be flexible and configurable for your use case. You can enable metrics or rules individually, or have both metrics and rules enabled.
To configure DCM, add a dcm entry to analysis_options.yaml:
dcm:
exclude-public-api: # configures the "exclude-public-api" mode for the commands that use it
extends:
- ... # configures the list of preset configurations
exclude:
all:
- ... # configures the list of files that should be ignored by supported excludes
rules:
- ... # configures the list of files that should be ignored by rules
metrics:
- ... # configures the list of files that should be ignored by metrics
unused-code:
- ... # configures the list of files that should be ignored by check-unused-code
unused-files:
- ... # configures the list of files that should be ignored by check-unused-files
parameters:
- ... # configures the list of files that should be ignored by check-parameters
dependencies:
- ... # configures the list of files that should be ignored by check-dependencies
code-duplication:
- ... # configures the list of files that should be ignored by check-code-duplication
unnecessarily-public-code:
- ... # configures the list of files that should be ignored by check-unnecessarily-public-code
unnecessarily-mutable-fields:
- ... # configures the list of files that should be ignored by check-unnecessarily-mutable-fields
exports:
- ... # configures the list of files that should be ignored by check-exports-completeness
formatter:
- ... # configures the formatter
metrics:
- ... # configures the list of reported metrics
pubspec-rules:
- ... # configures the list of rules for pubspec.yaml
rules:
- ... # configures the list of rules
project: # configures the project id for DCM Dashboards (Enterprise only)
project-tags:
- ... # configure the list of tags for DCM Dashboards (Enterprise only)
This configuration is used by both CLI and the IDE analyzer.
Basic config example:
dcm:
rules:
- avoid-dynamic
- avoid-passing-async-when-sync-expected
- avoid-redundant-async
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
- avoid-unused-parameters
- avoid-nested-conditional-expressions
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else
- prefer-moving-to-variable
- prefer-match-file-name
- avoid-collapsible-if
- avoid-redundant-else
- avoid-incomplete-copy-with
- avoid-self-compare
- avoid-self-assignment
- avoid-unnecessary-nullable-return-type
- avoid-unrelated-type-casts
- prefer-declaring-const-constructor
You can find a list of recommended rules here.
Basic config with metrics:
dcm:
metrics:
cyclomatic-complexity:
threshold: 20
number-of-parameters:
threshold: 4
maximum-nesting-level:
threshold: 5
exclude:
metrics:
- test/**
rules:
- avoid-dynamic
- avoid-passing-async-when-sync-expected
- avoid-redundant-async
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
- avoid-unused-parameters
- avoid-nested-conditional-expressions
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else
- prefer-moving-to-variable
- prefer-match-file-name
- avoid-collapsible-if
- avoid-redundant-else
- avoid-incomplete-copy-with
- avoid-self-compare
- avoid-self-assignment
- avoid-unnecessary-nullable-return-type
- avoid-unrelated-type-casts
- prefer-declaring-const-constructor
You can find a list of recommended metrics here.
Configuration-related Issues
Ignore Issues
Ignore issues are synthetic issues produced by the analyzer when parsing ignore comments (// ignore: and // ignore_for_file: ). Such issues do not have corresponding rules and cannot be ignored or enabled/disabled.
| Issue name | Description |
|---|---|
| avoid-duplicate-ignores | Highlights ignores that appear more than once. |
| avoid-unused-ignores | Highlights ignores that have no effect. |
Configuration Issues
Configuration issues are synthetic issues produces by the analyzer when parsing the analysis_options.yaml file. Such issues do not have corresponding rules and cannot be ignored or enabled/disabled.
| Issue name | Description |
|---|---|
| duplicate-rule | Highlights a rule that is added to the list of rules more than one time. |
| unknown-rule | Highlights a rule that does not match any known rule name. |
| not-available-rule | Highlights a rule that is not available to your pricing plan. |
| config-not-available | Highlights a rule configuration that is not available to your pricing plan. |
| empty-rule-config | Highlights a rule with an incorrect configuration resulting in an empty configuration. |
| unknown-rule-config | Highlights a rule that has an unknown configuration entry. |
| incorrect-rule-config | Highlights a rule that has an incorrect configuration entry. |
| requires-config | Highlights a rule that requires configuration to show any issues. |
| unknown-metric | Highlights a metric that does not match any known metric name. |
| empty-metric-config | Highlights a metric with an incorrect configuration resulting in an empty configuration. |
| unknown-metric-config | Highlights a metric that has an unknown configuration entry. |
| incorrect-metric-threshold | Highlights a metric that has an incorrect threshold value. |
| incorrect-metric-config | Highlights a metric that has an incorrect configuration entry. |
| preset-not-found | Highlights an unresolved or incorrect preset name. |
| incorrect-preset-config | Highlights an incorrectly configured preset. |
| presets-not-available | Highlights a preset that is not available to your pricing plan. |
| incorrect-exclude-public-api-config | Highlights an incorrectly configured exclude-public-api entry. |
| incorrect-exclude-config | Highlights an incorrectly configured exclude entry. |
| unknown-exclude-config | Highlights an incorrectly configured exclude subentry. |
| unknown-config | Highlights an unknown top-level config entry. |
Custom analysis_option.yaml Files
Aside from the regular analysis_option.yaml file, you can add a custom config file that matches one of the given patterns
- starts with
analysis_options(e.g. analysis_options.1.1.0.yaml) - starts with
dcm(e.g. dcm_config.yaml or dcm.yaml) - placed inside a folder called
dcm(e.g. dcm/config.yaml)
If such a file is referenced by any analysis_option.yaml file, DCM will correctly update configuration changes, validate rule names and display a configuration icon (⚙️) for configurable rules.
However, unlike for regular analysis_options.yaml files, code actions are not available.
IDE autocompletion
- VS Code
- IntelliJ / Android Studio
To enable configuration autocompletion, modify the settings.json to the following:
{
"[yaml]": {
"editor.quickSuggestions": {
"strings": "on"
}
}
}
No additional configuration is needed, simply modify any analysis_options.yaml file with DCM configuration to see the autocompletion results.
Excluding Public API
For commands that can affect the package's public API ("Check Unused Code", "Check Unused Files" and "Check Parameters"), setting the exclude-public-api entry in the analysis_options.yaml file will override the --exclude-public-api CLI option.
For example, if publicly exported files of a particular package are not expected to be changed, setting the exclude-public-api entry to true and running the command will exclude the public API only for that particular package.
dcm:
exclude-public-api: true # excludes public API for a particular package