Put spaces around binary operators (a + b). Exception: don't put spaces around the "range to" operator (0..i).
This rule currently seems to be implemented in SpacingAroundOperatorsRule.
Observed Behavior
No error is thrown during check and it is not formatted.
However, it is working correctly for these cases:
val foo1 = (null?:true)
val foo1 = null?:true
So I am only observing it for the !( ... ) cases.
Steps to Reproduce
Adding this test to SpacingAroundOperatorsRuleTest:
@Test
fun `Given operator inside !() missing spaces around the operator`() {
val code =
"""
val foo1 = !(null?:true)
val foo2 = !(7==7)
val foo3 = !(null?: true)
val foo4 = (null?:true)
val foo5 = null?:true
""".trimIndent()
val formattedCode =
"""
val foo1 = !(null ?: true)
val foo2 = !(7 == 7)
val foo3 = !(null ?: true)
val foo4 = (null ?: true)
val foo5 = null ?: true
""".trimIndent()
spacingAroundOperatorsRuleAssertThat(code)
.hasLintViolations(
LintViolation(1, 18, "Missing spacing around \"?:\""),
LintViolation(2, 15, "Missing spacing around \"==\""),
LintViolation(3, 18, "Missing spacing before \"?:\""),
LintViolation(4, 17, "Missing spacing around \"?:\""),
LintViolation(5, 16, "Missing spacing around \"?:\""),
).isFormattedAs(formattedCode)
}
Results in this test failure:
[Lint errors which can be automatically corrected]
Expecting actual:
[LintViolationFields(line=4, col=17, detail=Missing spacing around "?:", canBeAutoCorrected=true),
LintViolationFields(line=5, col=16, detail=Missing spacing around "?:", canBeAutoCorrected=true)]
to contain exactly in any order:
[LintViolationFields(line=1, col=18, detail=Missing spacing around "?:", canBeAutoCorrected=true),
LintViolationFields(line=2, col=15, detail=Missing spacing around "==", canBeAutoCorrected=true),
LintViolationFields(line=3, col=18, detail=Missing spacing before "?:", canBeAutoCorrected=true),
LintViolationFields(line=4, col=17, detail=Missing spacing around "?:", canBeAutoCorrected=true),
LintViolationFields(line=5, col=16, detail=Missing spacing around "?:", canBeAutoCorrected=true)]
but could not find the following elements:
[LintViolationFields(line=1, col=18, detail=Missing spacing around "?:", canBeAutoCorrected=true),
LintViolationFields(line=2, col=15, detail=Missing spacing around "==", canBeAutoCorrected=true),
LintViolationFields(line=3, col=18, detail=Missing spacing before "?:", canBeAutoCorrected=true)]
...
Your Environment
Version of ktlint used: current master branch faf8f66f48fb699820ebfaa9f6a653c1b5e872a7
Expected Behavior
Given this code:
It should be a lint violation, and formatted to the following to match what IntelliJ does:
Kotlin Coding Conventions: Horizontal whitespace
This rule currently seems to be implemented in SpacingAroundOperatorsRule.
Observed Behavior
No error is thrown during check and it is not formatted.
However, it is working correctly for these cases:
So I am only observing it for the
!( ... )
cases.Steps to Reproduce
Adding this test to SpacingAroundOperatorsRuleTest:
Results in this test failure:
Your Environment
master
branch faf8f66f48fb699820ebfaa9f6a653c1b5e872a7