Configuring Rules
Rules are one of the core building blocks of DCM. A rule validates if your code meets a certain expectation, and what to do if it does not meet that expectation.
All rules can be configured with severity, ignorable, effort, exclude and include options, but some rules also have additional configuration options specific to that rule and are marked with ⚙️.
Enabling a Rule
To enable a rule add its id to the rules entry:
dcm:
rules:
- newline-before-return
Rule Severities
To change a rule's severity, configure the rule with one of these values:
| Severity level | Description |
|---|---|
| error | By default, not assigned to any rule. Expected to represent most important issues. |
| warning | Assigned by default to rules that cover potential bugs. |
| style | Assigned by default to rules covering style issues. |
dcm:
rules:
- newline-before-return:
severity: style
Disabling Rule Ignores
To disable ignore comments for a particular rule, set ignorable: false:
dcm:
rules:
- newline-before-return:
ignorable: false
Customizing Estimated Effort
To change the estimated effort for a particular rule, set effort (in minutes):
dcm:
rules:
- newline-before-return:
effort: 10
Providing Additional Context
To include an additional message to the rule's default message, set message:
dcm:
rules:
- avoid-non-null-assertion:
message: 'Use our custom function "customFn" instead.'
This will change the avoid-non-null-assertion's message to Avoid non-null assertions. Try rewriting the code without it. Use our custom function "customFn" instead..
Excluding Files
To exclude specific files from rule's analysis, configure the exclude option:
dcm:
rules:
- newline-before-return:
exclude:
- test/**
Excluding Files for All Rules
To exclude a file for all rules, configure the global exclude:rules: option:
dcm:
exclude:
rules:
- test/**
- lib/src/some_file.dart
Including Files
To include specific files to rule's analysis, configure the rule include option:
dcm:
rules:
- newline-before-return:
include:
- test/**
All files are included by default.
Disabling a Rule
If you include an analysis options file (which has DCM configuration) or use a preset, you might want to disable some of the included rules. Disabling individual rules is similar to enabling them, but the name of a rule should be followed by either : false or : true.
Here's an example of an analysis options file that has a disabled rule:
include: package:my_lints/all.yaml
dcm:
rules:
- newline-before-return: false