Skip to main content

Excluding Code from Analysis

info

DCM also excludes files listed in the analyzer exclude: option. For example,

analysis_options.yaml
analyzer:
exclude:
- 'example/**'
- 'build/**'
- '**/*.g.dart'
- '**/*.freezed.dart'

will also disable DCM analysis for the listed files.

Using Comments

info

Ignore comments that don't actually ignore any rule diagnostic will be highlighted with "avoid-unused-rule-ignores" issues.

To ignore a specific rule warning, add // ignore comment:

// ignore: no-empty-block
void emptyFunction() {}

End-of-line comments are supported as well. The following communicates the same:

void emptyFunction() {} // ignore: no-empty-block

To ignore a rule for an entire file, use the ignore_for_file comment. For example,

// ignore_for_file: no-empty-block
...

void emptyFunction() {}

It's the same approach that the dart linter package use.

To ignore all lint rules, use // ignore_for_file: type=lint.

Commands also support ignore via comments. For example, ignore_for_file: unused-code comment will suppress unused code check for an entire file.

info

Although it's not recommended to suppress metrics, they can also be suppressed via // ignore: and // ignore_for_file: comments.

To ignore all metrics for a particular method, use // ignore: metrics.

To ignore all metrics, use // ignore_for_file: type=metrics.

Using Configuration

If you want a specific rule to ignore files, you can configure exclude entry for it. For example,

analysis_options.yaml
dart_code_metrics:
rules:
- no-equal-arguments:
exclude:
- test/**