Closed JLLeitschuh closed 5 years ago
Can I try to implement this one?
@AleksandrSl That would be great! As a starting point - take a look at https://github.com/shyiko/ktlint/blob/master/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/KtLint.kt#L397.
I'm not sure how to map compiler warnings to rule ids, though (RemoveCurlyBracesFromTemplate to string-template in this case; note that these two have different scope so in order to support @Suppress
rules will need to have access to suppression ranges complicating the matter).
Current workaround is to use /* ktlint-disable string-template */
.
P.S. If you feel like helping adding missing https://kotlinlang.org/docs/reference/coding-conventions.html & https://android.github.io/kotlin-guides/style.html rules is of (much) greater value then fixing this particular issue.
@shyiko I thought to handle suppress annotation directly in this rule, however your suggestion seems more natural
@AleksandrSl I guess that would be OK too (+ easier to implement).
NOTE: @Suppress
can be applied pretty much anywhere.
@AleksandrSl you can check out how we suppress issues by annotations @detekt, maybe it helps.
@shyiko Hi, I've come up with two draft implementations
https://github.com/AleksandrSl/ktlint/pull/2 - this one acts by adding SupressHint
s. Disadvantage - we suppress the whole string-template rule.
https://github.com/AleksandrSl/ktlint/pull/1 - this one acts in string-template rule. Disadvantage - we should scan all annotated parents of each node.
Hi @shyiko, did you have time to see proposed implementations, or this issue will be resolved by global changes in the way ktlint works?
I'd go with https://github.com/AleksandrSl/ktlint/pull/2 (only it should be it.toSet() instead of setOf() if I'm reading it right).
Doing some triage, it looks like the PR AleksandrSI#2 has been merged. Can this issue be closed @shyiko @AleksandrSl ?
@blcooley It was merged only in my fork) Here https://github.com/shyiko/ktlint/pull/263 is not merged yet. @shyiko what should we do with it?
Doing some triage, looks like #263 can be merged and this issue closed, @shyiko WDYT?
PR with support was merged.
If I have some code like this:
Ktlint reformats it to this:
The reason that I've put on the
@Suppress("RemoveCurlyBracesFromTemplate")
is because I want to have the "fake" indentation to be consistent. As you can see the character count between$TAB
is off by two characters from${TAB}
. I'm going for readability in my test over what is the "most correct".