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

Negative spacing during indent formatting #1188

Closed
cldfzn opened this issue Jul 29, 2021 · 3 comments · Fixed by #1192
Closed

Negative spacing during indent formatting #1188

cldfzn opened this issue Jul 29, 2021 · 3 comments · Fixed by #1192

Comments

@cldfzn
Copy link

cldfzn commented Jul 29, 2021

Expected Behavior

No exception

Observed Behavior

Stacktrace:

Caused by: java.lang.IllegalArgumentException: Count 'n' must be non-negative, but was -4.
        at kotlin.text.StringsKt__StringsJVMKt.repeat(StringsJVM.kt:737)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.visitWhiteSpace(IndentationRule.kt:1085)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.access$visitWhiteSpace(IndentationRule.kt:103)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule$indent$2.invoke(IndentationRule.kt:600)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule$indent$2.invoke(IndentationRule.kt:463)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:230)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:231)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.indent(IndentationRule.kt:462)
        at com.pinterest.ktlint.ruleset.standard.IndentationRule.visit(IndentationRule.kt:162)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:391)

Steps to Reproduce

With ktlint 0.42.0, the following fails when formatting:

class ApplicationContextSpec(private val applicationContext: ApplicationContext) : BehaviorSpec({
    Given("something") {
        When("run") {
            Then("it should do something") {
                applicationContext.getBean(Bean::class.java) shouldNotBe null
            }
        }
    }
}) {
    @MockkBean
    lateinit var other: OtherBean
}

Your Environment

  • Version of ktlint used: 0.42.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
  • Version of Gradle used (if applicable): 7.1
  • Operating System and version: macOS 10.15
  • Link to your project (if it's a public repository):
@shashachu shashachu added the bug label Jul 29, 2021
@shashachu
Copy link
Contributor

Thanks for the report @cldfzn. Can you confirm this is new in 0.42.0?

@cldfzn
Copy link
Author

cldfzn commented Jul 30, 2021

Yeah, I was testing out the upgrade from 0.41.0 to 0.42.0.

@shashachu
Copy link
Contributor

I'm planning on a 0.42.1 release since this was a regression introduced to 0.42.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants