detekt uses a yaml style configuration file for various things:
- rule set and rule properties
- build failure
- test-pattern to exclude rule sets/rules for test classes
- console and output formats
- autoCorrect support
See the default-detekt-config.yml file for all defined configuration options and their default values.
Note: When using a custom config file, the default values are ignored unless you also set the
Rule sets and rules
detekt allows easily to just pick the rules you want and configure them the way you like. For example if you want to allow 20 functions inside a kotlin file instead of the default threshold of 10, write:
complexity: TooManyFunctions: threshold: 20
To read about all supported rule sets and rules, use the side navigation
The configuration file contains a whole section to treat test code differently. Specify test patterns to detect test code and exclude rules or rule sets for them.
test-pattern: # Configure exclusions for test sources active: true patterns: # Test file regexes - '.*/test/.*' - '.*Test.kt' - '.*Spec.kt' exclude-rule-sets: - 'comments' exclude-rules: - 'NamingRules' - 'WildcardImport' - 'MagicNumber' - 'MaxLineLength' - 'LateinitUsage' - 'StringLiteralDuplication' - 'SpreadOperator' - 'TooManyFunctions'
Console and Output Reports
Uncomment the reporters you don’t care about.
console-reports: active: true exclude: # - 'ProjectStatisticsReport' # - 'ComplexityReport' # - 'NotificationReport' # - 'FindingsReport' # - 'BuildFailureReport' output-reports: active: true exclude: # - 'HtmlOutputReport' # - 'TxtOutputReport' # - 'XmlOutputReport'
Processors are usually used to raise project metrics. Uncomment the ones you do not care about.
processors: active: true exclude: # - 'FunctionCountProcessor' # - 'PropertyCountProcessor' # - 'ClassCountProcessor' # - 'PackageCountProcessor' # - 'KtFileCountProcessor'
This option is still present due to legacy reasons. In the first milestone releases detekt also formatted kotlin code.
Within the detekt team we decided to not mess with user code and let other tools do the formatting eg. intellij or KtLint.
Still as detekt can be extended with custom rules, you are free to write rules which support auto correction.
Only write correcting code within the