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

Prevent conflict when curly closing brace is followed by range (until) operator #2554

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}