Excluding Code from Analysis
DCM also excludes files listed in the analyzer exclude: option. For example,
analyzer:
exclude:
- 'example/**'
- 'build/**'
- '**/*.g.dart'
- '**/*.freezed.dart'
will also disable DCM analysis for the listed files.
Using Comments​
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 disable ignores for a particular rule or metric, set ignorable: false:
dcm:
rules:
- no-empty-block:
ignorable: false
metrics:
cyclomatic-complexity:
threshold: 20
ignorable: false
To ignore a rule for an entire file, use the ignore_for_file comment. For example,
// ignore_for_file: no-empty-block
...
void emptyFunction() {}
To ignore a rule for pubspec.yaml, use # ignore and # ignore_for_file comments, For example,
name: some_package
dependencies:
some_dependency: ^1.0.0 # ignore: prefer-pinned-version-syntax
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.
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​
Excluding Rules​
To exclude specific files from the rules analysis, configure the exclude option:
dcm:
rules:
- no-equal-arguments:
exclude:
- test/**
To exclude a file for all rules, configure the global exclude:rules: option:
dcm:
exclude:
rules:
- test/**
- lib/src/some_file.dart
Excluding Unused Code​
To exclude a file from the unused code analysis, configure the global exclude:unused-code: option:
dcm:
exclude:
unused-code:
- test/**
- lib/src/some_file.dart
Excluding Unused Files​
To exclude a file from the unused files analysis, configure the global exclude:unused-files: option:
dcm:
exclude:
unused-files:
- test/**
- lib/src/some_file.dart
Excluding Parameters​
To exclude a file from the parameters analysis, configure the global exclude:parameters: option:
dcm:
exclude:
parameters:
- test/**
- lib/src/some_file.dart
Excluding Dependencies​
To exclude a file from the dependencies analysis, configure the global exclude:dependencies: option:
dcm:
exclude:
dependencies:
- test/**
- lib/src/some_file.dart
Excludes for All Commands​
To configure excludes for all commands, set the exclude:all: option:
dcm:
exclude:
all:
- test/**
- lib/src/some_file.dart