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 and the threshold to the metrics
entry:
dcm:
metrics:
cyclomatic-complexity:
threshold: 20
To simply collect metric values without getting metric violations (for example, for DCM Dashboards), you can set the threshold
to unset
.
dcm:
metrics:
cyclomatic-complexity:
threshold: unset
Note that by default, metric violation below the threshold are not reported. To view all metric values in your console, use the --report-all
flag.
Setting Multiple Thresholds
To set multiple thresholds for a particular metrics, set entries
:
dcm:
metrics:
cyclomatic-complexity:
threshold: 20
entries:
- threshold: 10
paths:
- '.*some_folder.*'
- '.*some_file.dart'
- threshold: unset
paths:
- '.*another_folder'
Each entry expects a threshold and a list of paths (which are regular expressions).
Configuring the main threshold is required as that threshold will be used for file that are not covered by the entries
config (if no threshold is set, the default threshold will be used instead).
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
.
Disabling Metric Ignores
To disable ignore comments for a particular metric, set ignorable: false
:
dcm:
metrics:
cyclomatic-complexity:
threshold: 20
ignorable: false
Customizing Estimated Effort
To change the estimated effort for a particular metric, set effort
(in minutes):
dcm:
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:
dcm:
exclude:
metrics:
- test/**
- lib/src/some_file.dart