Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run same rule multiple times with different configuration #7263

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BraisGabin
Copy link
Member

@BraisGabin BraisGabin commented May 6, 2024

Ok, this is a NOT FINISHED work. But I wanted to share with you that after all those PRs detekt is able to run multiple instances of the same rule with different configurations.

I have this configuration:

  ForbiddenImport/AtProductionCode:
    active: true
    imports:
      - value: 'io.gitlab.arturbosch.detekt.api.Entity'
        reason: 'Import Assertions.assertThat instead.'
    excludes: ['**/test/**', '**/*Test.kt', '**/*Spec.kt']
  ForbiddenImport/AtTestCode:
    active: true
    imports:
      - value: 'io.gitlab.arturbosch.detekt.api.Entity'
        reason: 'Import Assertions.assertThat instead.'
    includes: ['**/test/**', '**/*Test.kt', '**/*Spec.kt']

And it produces this output:

detekt/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/KT.kt:6:1: The import `io.gitlab.arturbosch.detekt.api.Entity` has been forbidden: Import Assertions.assertThat instead. [ForbiddenImport/AtTestCode]
detekt/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/AnalyzerSpec.kt:8:1: The import `io.gitlab.arturbosch.detekt.api.Entity` has been forbidden: Import Assertions.assertThat instead. [ForbiddenImport/AtTestCode]
detekt/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/SuppressorsSpec.kt:6:1: The import `io.gitlab.arturbosch.detekt.api.Entity` has been forbidden: Import Assertions.assertThat instead. [ForbiddenImport/AtTestCode]
detekt/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/Builders.kt:4:1: The import `io.gitlab.arturbosch.detekt.api.Entity` has been forbidden: Import Assertions.assertThat instead. [ForbiddenImport/AtTestCode]
detekt/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt:8:1: The import `io.gitlab.arturbosch.detekt.api.Entity` has been forbidden: Import Assertions.assertThat instead. [ForbiddenImport/AtProductionCode]

And you can see at the end that one rule reports the files inside test and the other inside main. 馃帀

There is still work to make this production ready but it is happening!

@cortinico
Copy link
Member

And it produces this output:

The output has rule ids like [ForbiddenImport/AtTestCode] while in your config you have ForbiddenImport/2 and /3. I assume that's a mistake

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this :D

@@ -1,3 +1,6 @@
config:
validation: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation code doesn't know about this type of config keys yet. I need to implement that. I disabled it just to make it work for now. As I said this is still not ready to merge. I just wanted to share it to show that this is near to be done.

@BraisGabin
Copy link
Member Author

And it produces this output:

The output has rule ids like [ForbiddenImport/AtTestCode] while in your config you have ForbiddenImport/2 and /3. I assume that's a mistake

Indeed. Copy&paste error. I fixed it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants