Configuring Metrics
Metrics are one of the core building blocks of DCM. Metrics help you understand the complexity of your code and identify areas that may be difficult to maintain or test.
All metrics are configurable.
Enabling a Metric
To enable a metric add its id to the metrics
entry:
dart_code_metrics:
metrics:
cyclomatic-complexity: 20
Alternatively, the threshold can be set via the threshold
entry:
dart_code_metrics:
metrics:
cyclomatic-complexity:
threshold: 20
Understanding Metric Thresholds
The threshold is a value after which a calculated metric value is marked as a violation.
Some metric thresholds can be any positive number (for example, 20
or 200
), while others can only be a number between 0
and 1
.
Additionally, some metric threshold are inverted (meaning, the lower the calculated value, the higher the severity level of the violation). For example, weight-of-class
takes a threshold value from 0
and 1
, and with the configured threshold of 0.33
, a calculated value of 0.1
will be marked as a Very High
level of violation.
Each calculated metric value falls into one of four violation levels (based on the configured threshold) - Very High
, High
, Near
, and Below
.
Violation level | Regular threshold | Inverted threshold |
---|---|---|
Very High | > 200% | < 50% |
High | 100% - 200% | 50% - 100% |
Near | 80% - 100% | 100% - 125% |
Below | < 80% | > 125% |
All % values are relative to the configured threshold.
For example, if the cyclomatic complexity of a method is 30
(and the threshold is 20
), the value falls into the High
level. And all values above 40
will be marked as Very High
.
Customizing Estimated Effort
To change the estimated effort for a particular metric, set effort
(in minutes):
dart_code_metrics:
metrics:
cyclomatic-complexity:
threshold: 20
effort: 10
If you are setting custom estimated effort, don't forget to set threshold
.
Excluding Files for All Metrics
To exclude files from a metrics report, provide a list of glob patterns for ignored files:
dart_code_metrics:
exclude:
metrics:
- test/**
- lib/src/some_file.dart