Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ktlint indentation rule has problems with disable check on a single line #1645

Closed
zsqw123 opened this issue Sep 11, 2022 · 2 comments
Closed

Comments

@zsqw123
Copy link
Contributor

zsqw123 commented Sep 11, 2022

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

paul-dingemans added a commit to zsqw123/ktlint that referenced this issue Sep 14, 2022
@paul-dingemans
Copy link
Collaborator

Reference to PR #1646 is invalid. This issue is not fixed by that PR.

@paul-dingemans
Copy link
Collaborator

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.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants