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 ignoring braces #1644

Closed
zsqw123 opened this issue Sep 11, 2022 · 1 comment
Closed

ktlint indentation rule has problems with ignoring braces #1644

zsqw123 opened this issue Sep 11, 2022 · 1 comment

Comments

@zsqw123
Copy link
Contributor

zsqw123 commented Sep 11, 2022

Expected Behavior

The following code should not be formatted
image

Observed Behavior

But when I run ktlint -F, I get the following.
image

Steps to Reproduce

fun main() {
    fun innerFun0() {
        // some code
    } // ktlint-disable

    fun innerFunc1() {
        // some code
    }
}

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 indentation rule records the braces with a stack, and when I use // ktlint-disable on the line where the braces are, the indentation rule does not check this ASTNode and the stack does not change, hence the problem.

@zsqw123
Copy link
Contributor Author

zsqw123 commented Sep 11, 2022

I think the solution to this is simply to make ktlint always perform a visit for each node. But for nodes that do not require format, we do not modify them

@zsqw123 zsqw123 changed the title ktlint indentRule has problems with ignoring braces ktlint indentation rule has problems with ignoring braces Sep 11, 2022
paul-dingemans added a commit to zsqw123/ktlint that referenced this issue Sep 16, 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

1 participant