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

Will Hawkins

02/03/2020, 9:45 PM
A related question, perhaps: Where is the best place to put a check on the user-specified configuration for a particular custom ruleset?
s

schalkms

02/06/2020, 7:26 PM
w

Will Hawkins

02/08/2020, 8:10 AM
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

schalkms

02/08/2020, 8:26 AM
Sure, you can do that in the rule when fetching the config option. After that you can validate it ofc.
w

Will Hawkins

02/08/2020, 8:41 AM
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

Artur Bosch

02/18/2020, 5:17 AM
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

Will Hawkins

02/18/2020, 4:02 PM
That's a great idea, @Artur Bosch. Would you be open to a PR for handling this in a more "standard" way?
a

Artur Bosch

02/19/2020, 9:33 PM
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

Will Hawkins

02/20/2020, 6:52 AM
oh wow. Perhaps. I am checking that now, thanks!
5 Views