https://kotlinlang.org logo
Title
e

eygraber

04/26/2023, 7:14 PM
Has there ever been a discussion about providing a "simpler" API for Rules? For example, I'm porting some rules that I wrote for detekt and I find the detekt rule API to be very pleasant to work with.
s

Sha Sha Chu

04/26/2023, 7:22 PM
can you be a bit more specific about what seems harder than it needs to be?
e

eygraber

04/26/2023, 8:02 PM
Detekt has some nice abstractions around working with psi and KtFile. Looks like most of that is supplied through the Kotlin compiler's KtVisitorVoid and then some wiring through detekt's BaseRule. Having the convenience functions from
KtVisitorVoid
are very helpful and make development simpler (at least from my perspective). It looks like ktlint just extracts the root AST node from the KtFile and operates using AST.
s

Sha Sha Chu

04/26/2023, 8:03 PM
ah. yes, i can see us providing some abstractions or extensions if necessary. depending on what you need to do, it does sometimes require custom traversal of the AST
e

eygraber

04/26/2023, 8:45 PM
Yeah I expect to have to do custom traversal in some cases, but for certain cases it seems like there's a lot of non trivial repetition across rules (e.g. traversing the AST to find a
when
vs having a
visitWhen
function)
s

Sha Sha Chu

04/27/2023, 3:11 PM
that makes a lot of sense. if you wouldn't mind writing an issue we can consider it for the 1.0 release or later