Skip to content

Commit

Permalink
Prevent conflict when curly closing brace is followed by range (until…
Browse files Browse the repository at this point in the history
…) operator

Closes #2359
  • Loading branch information
paul-dingemans committed Feb 17, 2024
1 parent 8eb0a58 commit 0b6dcd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LAMBDA_EXPRESSION
import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACE
import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACKET
import com.pinterest.ktlint.rule.engine.core.api.ElementType.LPAR
import com.pinterest.ktlint.rule.engine.core.api.ElementType.RANGE
import com.pinterest.ktlint.rule.engine.core.api.ElementType.RANGE_UNTIL
import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE
import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACKET
import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR
Expand Down Expand Up @@ -182,7 +184,9 @@ public class SpacingAroundCurlyRule :
nextElementType == EXCLEXCL ||
nextElementType == LBRACKET ||
nextElementType == LPAR ||
nextElementType == COLONCOLON
nextElementType == COLONCOLON ||
nextElementType == RANGE ||
nextElementType == RANGE_UNTIL
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,22 @@ class SpacingAroundCurlyRuleTest {
.isFormattedAs(formattedCode)
}
}

@Test
fun `Issue 2359 - Given RBRACE followed by range operator then do not emit`() {
val code =
"""
val foo = emptyList<String>().count { true }..1
""".trimIndent()
spacingAroundCurlyRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2359 - Given RBRACE followed by range until operator then do not emit`() {
val code =
"""
val foo = emptyList<String>().count { true }..<2
""".trimIndent()
spacingAroundCurlyRuleAssertThat(code).hasNoLintViolations()
}
}

0 comments on commit 0b6dcd9

Please sign in to comment.