Ktlint: Make ktlint follow @Suppress/@SuppressWarning annotations

Created on 4 Jun 2020  路  2Comments  路  Source: pinterest/ktlint

I just read #263 thinking it would also provide a way to use @Suppress/@SuppressWarning for the other rules but it's only for RemoveCurlyBracesFromTemplate.

I was going to make a PR to fix the issue but I'd like to discuss possible implementations.

Currently

Annotations are read and the rule name inside is then mapped to the ktlint rule-name.
(RemoveCurlyBracesFromTemplate is the rule name from Jetbrains Kotlin code inspections for Intellij)
https://github.com/pinterest/ktlint/blob/3a87624c43b3ea0936cfe5a278d5749921eec129/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt#L482-L518

To support other rules

  1. Use ktlint rule name inside suppress annotations
  2. Use Jetbrains rules name inside suppress annotations and map it to ktlint rule name (if it exists, otherwise create a PascalCase name).

In the second case, we could either keep the suppressAnnotationRuleMap and just add every rule inside of it, which is not SOLID since every time a rule is added, this map needs to change and it's not really the concern of Ktlint object to know it's rules' name...
The other solution would be to add an attribute suppressRuleName to Rule so that every rule will have it's own.

The argument of using @Suppress along with Kotlin code inspections name would be to have both your favorite editor and ktlint inspection support it.

enhancement proposal

All 2 comments

suppressAnnotationRuleMap is a temp workaround until better solution. Ideally rules themselves should provide such information, rather then collect it inside KtLint.kt.

Let me think how to do it properly and come back to you.

Hey @Tapchicoma did you have so spare time to think about this ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZakTaccardi picture ZakTaccardi  路  4Comments

Tapchicoma picture Tapchicoma  路  3Comments

filipedelimabrito picture filipedelimabrito  路  3Comments

artnc picture artnc  路  3Comments

jbarr21 picture jbarr21  路  5Comments