Hello people. Is it possible to have a master conf...
# detekt
d
Hello people. Is it possible to have a master config file + another file for custom rules only? Use case More teams share the same config, which is fetched from a shared repo and ensures every team follows the same rule-set. But each team should be able to extend Detekt to create additional rules. What is the right way to define a configuration for additional rules only? Additional extra info I noticed that
detekt.config
accepts multiple files, but I’m unsure how it works. Do they have a particular priority? How could we add more than 1 config file to the Detekt plugin?
g
Yes you can specify multiple config files and they will get merged.
d
Thanks, but the original rule-set mustn’t be affected ( rules cannot be overridden ). Is there a priority order? Also, how to set up more than 1 config to the plugin? I tried to add them comma-separated into
configPaths
but didn’t work 😄
t
Copy code
detekt {
    // option 1
    config = files("path1", "path2")
    // option 2
    config.from("path1", "path2")
}

tasks.withType(io.gitlab.arturbosch.detekt.Detekt).configureEach {detektTask ->
    // only option 2 available for task level configuration
    config.from("path1, path2")
}
@Davide Giuseppe Farella
It’s a FileColleciton, not a list, so gradle handles it in a special way
d
So basically, given
path1
had
SomeRule: active: true
and
path2
has
SomeRule: active: false
there's no guarantee whether the rule will be active or not, correct? So, unless I wanna merge the 2 files manually, I guess the only option is not telling the teams that rules can be overridden 😄
t
Not sure exactly how the precedence is decided. I’m sure it’s deterministic in some way. But if you don’t like it, you can always write a task to merge (and optionally, validate) your configs in a way that’s appropriate to you, and use the output of that task as the config for detekt.
d
Yes, but I wanna limit the required work for now, maybe ad a second step. Thank you. Also, when I asked about adding both of the config to the Plugin, I mean the IDE plugin 🙂 as the file picker doesn't allow picking multiple files; I tried editing the xml, without success
t
Oh I see, yeah, not sure on that one. I don’t think the IDE plugin supports custom rules anyways.
d
There's an option for additional jars, so I believe it does 🙂
t
Scratch that, you are correct. It does. I just didn’t configure mine correctly.
I wonder if it supports type resolution
The IDE seems to use colons to separate paths in that selection box
d
That's great! I'm goin to try that in a min! Thanks 😄
I might be wrong, but seems like the second is the one who wins 😄
Aka, rules from the second file override rules from the first one. So I guess I’ll do
files(custom-rules.yml, config.yml)
👍 1