ktlint
ktlint copied to clipboard
ktlint indentation rule has problems with disable check on a single line
Behavior
Like the code below, I want to disable the format of on the first .append
method, but that doesn't seem to work
fun main() {
StringBuilder()
.append("1") // ktlint-disable
.append("1")
// expect:
StringBuilder()
.append("1") // ktlint-disable
.append("1")
// but:
StringBuilder()
.append("1") // ktlint-disable
.append("1")
}
Steps to Reproduce
Using the code mentioned in Behavior, and run ktlint -F
Your Environment
- Version of ktlint used: 0.47
- No .editorconfig
- Version of Gradle used (if applicable): No
- Operating System and version: MacOS 12.5
Possible reasons
ktlint's rules use startOffset
for determining whether to disable, but PsiWhiteSpace
's startOffset
is on the previous line when it contains \n
, which seems to lead to this error
Reference to PR #1646 is invalid. This issue is not fixed by that PR.
I am not in favor of changing this behavior as I am considering to remove the ktlint-disable/ktlint-enable directives as the @Suppress("ktlint:all")
is more native.