From 0b6dcd926d1e4dd65270099401b0612c2bd1279b Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Sat, 17 Feb 2024 16:46:17 +0100 Subject: [PATCH] Prevent conflict when curly closing brace is followed by range (until) operator Closes #2359 --- .../standard/rules/SpacingAroundCurlyRule.kt | 6 +++++- .../rules/SpacingAroundCurlyRuleTest.kt | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt index b3f04be4fd..9412ca36a1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt @@ -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 @@ -182,7 +184,9 @@ public class SpacingAroundCurlyRule : nextElementType == EXCLEXCL || nextElementType == LBRACKET || nextElementType == LPAR || - nextElementType == COLONCOLON + nextElementType == COLONCOLON || + nextElementType == RANGE || + nextElementType == RANGE_UNTIL ) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRuleTest.kt index b47f7118d8..e13c618de9 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRuleTest.kt @@ -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().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().count { true }..<2 + """.trimIndent() + spacingAroundCurlyRuleAssertThat(code).hasNoLintViolations() + } }