Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Regression: strange behaviour of indent rules in v0.43.2 #1330

Closed
m-burst opened this issue Dec 30, 2021 · 0 comments · Fixed by #1358
Closed

Regression: strange behaviour of indent rules in v0.43.2 #1330

m-burst opened this issue Dec 30, 2021 · 0 comments · Fixed by #1358

Comments

@m-burst
Copy link

m-burst commented Dec 30, 2021

Expected Behavior

I've tried to upgrade from v0.40.0 to v0.43.2 and encountered a situation where the indent rule reports some strange violations.

Below is a minimal reproducible example of the issue via CLI:

ktlint --stdin <<EOF
fun func(lambdaArg: Unit.() -> Unit = { }, secondArg: Int) {
    println()
}
EOF

I'm expecting this code to be valid.

Observed Behavior

ktlint reports the following errors with the code above:

<stdin>:2:1: Unexpected indentation (4) (should be 0)
<stdin>:3:1: Unexpected indentation (0) (should be -4)

Steps to Reproduce

See code above

Your Environment

  • Version of ktlint used: 0.43.2
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): cli
  • Version of Gradle used (if applicable): n/a
  • Operating System and version:
  • Link to your project (if it's a public repository): n/a
@paul-dingemans paul-dingemans added this to the 0.44.0 milestone Jan 25, 2022
paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue Feb 2, 2022
…gument should not throw error

Making this possible required a considerable refactoring of the code.
The exceptions regarding formatting of blocks in conjunction with
the exceptions for the BY-keyword continually conflicted with each
other. Especially the exceptions for the BY-keyword were sometimes
incorrectly implemented.

The blockOpeningLineStack in the IndentContext has now been replaced
with a blockStack which contains more context information about the
block. Also trace logging now provides more details about opening
and closing blocks. The main idea behind this stack is however not
changed. But some functionality has been moved from the closing
element to the opening element.

Closes pinterest#1330
paul-dingemans added a commit that referenced this issue Feb 13, 2022
…gument should not throw error (#1358)

A single line function with a parameter having a lambda as default argument should not throw error

Making this possible required a considerable refactoring of the code.
The exceptions regarding formatting of blocks in conjunction with
the exceptions for the BY-keyword continually conflicted with each
other. Especially the exceptions for the BY-keyword were sometimes
incorrectly implemented.

The blockOpeningLineStack in the IndentContext has now been replaced
with a blockStack which contains more context information about the
block. Also trace logging now provides more details about opening
and closing blocks. The main idea behind this stack is however not
changed. But some functionality has been moved from the closing
element to the opening element.

Closes #1330

Co-authored-by: Paul Dingemans <pdingemans@bol.com>
Co-authored-by: Sha Sha Chu <shasha@pinterest.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants