Detekt: Allow globally defined exclusion pattern

Created on 5 Apr 2020  路  3Comments  路  Source: detekt/detekt

Expected Behavior

I would like to be able to globally edit the exclusion patterns, rather than chaning them one by one for each rules.

Current Behavior

Currently each rules has its own exclusion pattern. That leads to a lot of repetition in the config files, and it is especially annoying and error prone when it is time to change the patterns as we are forced to go through all of them one by one.

Context

I introduced new test source sets in a project and I have to tell detekt to ignore that sourceset for a bunch of rules. Which rules? Simple, all the rules that are already excluding the test sources.

But instead of having to change one line to tell detekt what are the patterns of test sources, I have to go through each rules and edit them one by one.

The configuration styled proposed by #775 would have been perfect.

api core feature

Most helpful comment

New format proposed in #2851

exclusion-patterns:
  - 'dont apply in tests':
    patterns:
      - '**/test/**'
      - '**/androidTest/**'
      - '**/commonTest/**'
    rules:
      - 'comments'
  - 'mappers are an special case too':
    patterns:
      - '**/jvmTest/**'
      - '**/jsTest/**'
      - '**/iosTest/**'
    rules:
      - 'potential-bugs>LateinitUsage'
      - 'style>MagicNumber'
      - 'style>WildcardImport'

All 3 comments

I like the current way to exclude because it allows you to tune your config a lot. But I have the same problem as @jcornaz. I think that detekt should support the current exclusion method and the proposed in #775 or similar. My proposal is:

exclusion-patterns:
- patterns:
    - **/test/**
    - **/androidTest/**
    - **/*.Test.kt
    - **/*.Spec.kt
    - **/*.Spek.kt
  rules:
    - VariableNaming
    - FunctionNaming
- patterns:
    - *DTO.kt
  rules:
    - Rule4
    - Rule8
...

To give more context I'm going to explain my use case:

Every time that I update detekt I run --generate-config. This rewrites ALL my configurations so then I go change by change checking if I prefer the new defautl configuration or my old one. I do this because I like the have all the posible parameters in the configuration file so if I need to tune any rule I don't need to check any documentation.

This was not a big problem because I have just a few changes in my configuration file so the changes to check were few. But two month ago I added a new source route for my tests. And now I need to revert 24 lines each time that I update detekt.

With the proposed format I should just need to revert one removed line.

New format proposed in #2851

exclusion-patterns:
  - 'dont apply in tests':
    patterns:
      - '**/test/**'
      - '**/androidTest/**'
      - '**/commonTest/**'
    rules:
      - 'comments'
  - 'mappers are an special case too':
    patterns:
      - '**/jvmTest/**'
      - '**/jsTest/**'
      - '**/iosTest/**'
    rules:
      - 'potential-bugs>LateinitUsage'
      - 'style>MagicNumber'
      - 'style>WildcardImport'
Was this page helpful?
0 / 5 - 0 ratings