You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running detekt with the ktlint formatter set enabled (see attached reproducer project), the IndentationRule which is called in ktlint intermittently sees a failure during parsing.
Config:
# full detekt.yml in attached project
formatting:
Indentation:
active: true
autoCorrect: true
indentSize: 4
This occurs in a file that looks like the following, note the incorrect spacing here: (){
class XYZA {
fun tearDown(){
}
}
There was a similar issue reported a while back, #6357, but they could not provide reproduction steps.
Is this a bug in ktlint? What's the actual potential issue/root cause?
I don't think it's a bug in ktlint, and I tried to reproduce it in the ktlint project, checking out the tag that detekt uses, and then adding the following test runs successfully
> ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRuleTest.kt
@Test
fun `improperly spaced brackets should not crash`() {
val code =
"""
class XYZA {
fun tearDown(){
}
}
""".trimIndent()
indentationRuleAssertThat(code)
.hasNoLintViolations()
}
I also tried to test using the command line, but could not reproduce it.
Looking at both the source of the detekt/FormatterRule and the ktlint/IndentationRule, it looks like detekt is doing some pre-processing of the ASTNodes being sent to ktlint, so perhaps that could be the issue? In any case, the following code from ktlint seems to be ineffectively removing the nodes from the stack, causing an eventual validation error at the end of the rule.
override fun afterVisitChildNodes(node: ASTNode
...
while (indentContextStack.peekLast()?.toASTNode == node) {
indentContextStack.removeLast()
Which later causes the exception to be thrown in override fun afterLastNode() ... require(indentContextStack.isEmpty()).
Your Environment
Version of detekt used: 1.23.5 (but also reproduces on 1.23.3)
Version of Gradle used: 8.0, 8.2
Operating System and Java version: Java 17.0.2+8-LTS Mac OS X as well as Java 17.0.3+6-LTS Mac OS X
Now, the interesting bit, it might fail the first time, but generally fails on the second invocation
Run git reset --hard HEAD to dismiss autofixes (if present)
Run ./gradlew app:detekt again. You might have to repeat this process with or without the git reset to see the error, but I confirmed with a colleauge that they could repro on the third attempt on the sample project before sending this bug report
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Behavior
When running detekt with the ktlint formatter set enabled (see attached reproducer project), the
IndentationRule
which is called in ktlint intermittently sees a failure during parsing.Config:
Stacktrace:
This occurs in a file that looks like the following, note the incorrect spacing here:
(){
There was a similar issue reported a while back, #6357, but they could not provide reproduction steps.
Is this a bug in ktlint? What's the actual potential issue/root cause?
I don't think it's a bug in ktlint, and I tried to reproduce it in the ktlint project, checking out the tag that detekt uses, and then adding the following test runs successfully
I also tried to test using the command line, but could not reproduce it.
Looking at both the source of the
detekt/FormatterRule
and thektlint/IndentationRule
, it looks like detekt is doing some pre-processing of the ASTNodes being sent to ktlint, so perhaps that could be the issue? In any case, the following code from ktlint seems to be ineffectively removing the nodes from the stack, causing an eventual validation error at the end of the rule.Which later causes the exception to be thrown in
override fun afterLastNode() ... require(indentContextStack.isEmpty())
.Your Environment
Java 17.0.2+8-LTS Mac OS X
as well asJava 17.0.3+6-LTS Mac OS X
Steps to Reproduce
Given the following project
repro.zip
./gradlew app:detekt
.git reset --hard HEAD
to dismiss autofixes (if present)./gradlew app:detekt
again. You might have to repeat this process with or without the git reset to see the error, but I confirmed with a colleauge that they could repro on the third attempt on the sample project before sending this bug reportThanks in advance!
The text was updated successfully, but these errors were encountered: