OeditusCredo.Check.Refactoring.ChangeRiskAntiPatterns
(OeditusCredo v0.8.0)
View Source
Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of low and works with any version of Elixir.
Explanation
Functions that are both complex and under-tested are the riskiest to change. The CRAP (Change Risk Anti-Patterns) score surfaces them by combining cyclomatic complexity with test coverage:
CRAP = complexity^2 * (1 - coverage/100)^3 + complexityIMPORTANT: this check needs persisted coverage data and must be run AFTER generating it:
mix test --cover --export-coverage default
mix credoPlain mix test --cover does not leave an importable coverage file. When
no coverage data is available the check does nothing by default (set
require_coverage: true to flag that situation instead).
A high score is a prompt to investigate: add meaningful tests, simplify the function, or write characterization tests before refactoring risky legacy code. Cyclomatic complexity is only a proxy for path/test burden; it does not measure naming, cohesion, or whether tests assert anything meaningful.
Check-Specific Parameters
Use the following parameters to configure this check:
:max_score
The maximum CRAP score a function may have before it is reported.
This parameter defaults to nil.
:coverdata
Path to the persisted coverage file, relative to the project root (default cover/default.coverdata).
This parameter defaults to nil.
:exclude_test_files
Set to false to also score test files (default: true).
This parameter defaults to nil.
:require_coverage
When true, report an issue if coverage data is missing instead of silently skipping (default: false).
This parameter defaults to nil.
:coverage
Advanced/testing: an explicit %{{module, function, arity} => percent} map that bypasses coverdata loading.
This parameter defaults to nil.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.