A related question, perhaps: Where is the best pla...
# detekt
w
A related question, perhaps: Where is the best place to put a check on the user-specified configuration for a particular custom ruleset?
s
w
Thanks, @schalkms. It's not so much fetching those configurations, it's validating that they are correct. I know that each of the fields is validated according to their types, but in my case I want to be able to validate those fields based on a special semantic meaning. In other words, the configuration is a string and it validates as such. However, those strings should really be comma-delimited days of the week, for instance. I would like to be able to specify that when I am writing my rule and have detekt use that to validate. Does that make sense?
s
Sure, you can do that in the rule when fetching the config option. After that you can validate it ofc.
w
ofc I can do it on demand, but I'd love for that to be done at the same time as the overall config validation that detekt applies
@schalkms ^^
a
A bogus but valid way would be to implement a
FileProcessListener
, implement the
init
method to get the
Config
and validate it on
onFinish
and report any warnings to
Detektion#add
.
You also need to overwrite the default
console-reports>exclude
property
w
That's a great idea, @Artur Bosch. Would you be open to a PR for handling this in a more "standard" way?
a
Yes! Please take a look at following PR - https://github.com/arturbosch/detekt/pull/2356. In the scope of #2285 I've added a new ConfigValidator extension. Does it handle your usecase?
w
oh wow. Perhaps. I am checking that now, thanks!