https://kotlinlang.org logo
#detekt
Title
# detekt
j

Javier

11/19/2021, 11:59 AM
I have a convention plugin published with is using a default config for Detekt. I am using this plugin in a lot of repositories. The problem is I want to add default rules to it, without having to add them to the yaml of each repository which is using this convention plugin. Ideally should be great that there is a way to create rules as dependencies and add them to Detekt without having to specify them in the yaml. Potentially public API:
Copy code
detekt {
    rules {
        detektRule("com.example.rules:custom-rule-one:1.0.0")
        // alternatives: `implementation`, `add`, etc.
        // automatically applied without indicating it in the yaml
    }
}
Another solution can be merging yaml files via adding them to resource folders or something so, but I prefer the previous API.
b

Brais Gabin

11/19/2021, 12:02 PM
Do you look for something like this: https://github.com/detekt/detekt/issues/3242
j

Javier

11/19/2021, 12:07 PM
I have to read it deeply (time to eat!) but it looks similar 🙂
b

Brais Gabin

11/19/2021, 2:01 PM
Let me know if that would fix your use case because that's a feature that I want to fix from time ago (I don't like the dependencies between the core detekt and the formatting plugin). And if it would help your use case I have an extra motivation to do it. To be honest I'm missing it too for o custom rule that I have related with JUnit
j

Javier

11/19/2021, 2:18 PM
Yeah I think it is, do you have an example of how the public api would be?
b

Brais Gabin

11/19/2021, 2:27 PM
I think that something like this: https://github.com/detekt/detekt/blob/main/detekt-core/src/main/resources/deprecation.properties and https://github.com/detekt/detekt/blob/f12697d70045339b13dd31c88cba7fbfb997acdd/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfig.kt#L68-L76 Every library (or ruleSet) should create a file in the resources. That file should be the default configuration for that library. Then the core will only get all those files and concat them.
Then, we should create a tool to autogenerate those files in an easy way. detekt does have that already but it's not generic. It could be used easily by a third party.
What do you think? Does it have sense?
Ok, I have a first version implemented: https://github.com/detekt/detekt/pull/4315
👀 1
c

chao

11/22/2021, 6:27 PM
Actually I wrote a gradle plugin at my company to set the config for projects applying the plugin. It looks great that we can have this feature built-in.