diff --git a/formatter/src/main/kotlin/org/kotlin/formatter/output/TokenPreprocessor.kt b/formatter/src/main/kotlin/org/kotlin/formatter/output/TokenPreprocessor.kt index 42626ba..eb1b5cb 100644 --- a/formatter/src/main/kotlin/org/kotlin/formatter/output/TokenPreprocessor.kt +++ b/formatter/src/main/kotlin/org/kotlin/formatter/output/TokenPreprocessor.kt @@ -129,8 +129,8 @@ class TokenPreprocessor { resultStack.peek() .tokens .add(ForcedBreakToken(count = token.content.count { it == '\n' })) - } else if (!(lastToken is ForcedBreakToken || lastToken is - ClosingForcedBreakToken) + } else if (!(lastToken is ForcedBreakToken || + lastToken is ClosingForcedBreakToken) ) { resultStack.peek().tokens.add(token) } diff --git a/formatter/src/main/kotlin/org/kotlin/formatter/scanning/NodeScanner.kt b/formatter/src/main/kotlin/org/kotlin/formatter/scanning/NodeScanner.kt index e4fba94..c7b0907 100644 --- a/formatter/src/main/kotlin/org/kotlin/formatter/scanning/NodeScanner.kt +++ b/formatter/src/main/kotlin/org/kotlin/formatter/scanning/NodeScanner.kt @@ -121,11 +121,10 @@ internal class NodeScannerProvider( KtNodeTypes.WHEN_ENTRY, KtNodeTypes.ANNOTATION_ENTRY, KtNodeTypes.PREFIX_EXPRESSION, KtNodeTypes.VALUE_PARAMETER, KtNodeTypes.SUPER_TYPE_ENTRY, KtNodeTypes.SUPER_TYPE_CALL_ENTRY, KtNodeTypes.USER_TYPE, - KtNodeTypes.BINARY_WITH_TYPE, KtNodeTypes.DELEGATED_SUPER_TYPE_ENTRY -> - simpleBlockScanner.value + KtNodeTypes.BINARY_WITH_TYPE, KtNodeTypes.DELEGATED_SUPER_TYPE_ENTRY, + KtNodeTypes.IS_EXPRESSION -> simpleBlockScanner.value KtNodeTypes.SHORT_STRING_TEMPLATE_ENTRY, KtNodeTypes.LONG_STRING_TEMPLATE_ENTRY -> stringTemplateEntryScanner.value - KtNodeTypes.OBJECT_LITERAL -> simpleScanner.value else -> simpleScanner.value } } diff --git a/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt b/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt index b49420e..44f6290 100644 --- a/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt +++ b/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt @@ -1851,6 +1851,19 @@ class KotlinFormatterTest { ) } + @Test + fun `prefers not to break before is operator`() { + val result = + KotlinFormatter(maxLineLength = 26).format("val something = variable is MyClass") + + assertThat(result).isEqualTo( + """ + val something = + variable is MyClass + """.trimIndent() + ) + } + @Test fun `format breaks at logical operator in a while statement`() { val result =