Skip to content

Commit

Permalink
Revert D55330950: Preserve a trailing space when lambda only has bloc…
Browse files Browse the repository at this point in the history
…k comments

Differential Revision:
D55330950

Original commit changeset: ca9288b3b1b4

Original Phabricator Diff: D55330950

fbshipit-source-id: 3fb64d1aa01764d358154ac9b5747ea45d99cd04
  • Loading branch information
hick209 authored and facebook-github-bot committed Mar 28, 2024
1 parent fc1eac3 commit dedc790
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ class KotlinInputAstVisitor(
val valueParams = lambdaExpression.valueParameters
val hasParams = valueParams.isNotEmpty()
val statements = (lambdaExpression.bodyExpression ?: fail()).children
val hasComments = lambdaExpression.bodyExpression?.children()?.any { it is PsiComment } ?: false
val hasStatements = statements.isNotEmpty()
val hasArrow = lambdaExpression.functionLiteral.arrow != null

Expand Down Expand Up @@ -947,7 +946,7 @@ class KotlinInputAstVisitor(
}
}

if (hasParams || hasArrow || hasStatements || hasComments) {
if (hasParams || hasArrow || hasStatements) {
// If we had to break in the body, ensure there is a break before the closing brace
builder.breakOp(Doc.FillMode.UNIFIED, " ", bracePlusZeroIndent)
}
Expand Down
9 changes: 0 additions & 9 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5903,15 +5903,6 @@ class FormatterTest {
|"""
.trimMargin())

@Test
fun `lambda with only comments`() =
assertFormatted(
"""
|val a = { /* do nothing */ }
|val b = { /* do nothing */ /* also do nothing */ }
|"""
.trimMargin())

@Test
fun `chaining - many dereferences`() =
assertFormatted(
Expand Down

0 comments on commit dedc790

Please sign in to comment.