Skip to content

Commit

Permalink
Stop emitting multiple trailing commas in enum entry lists with multi…
Browse files Browse the repository at this point in the history
…line items (#458)

Summary: Pull Request resolved: #458

Reviewed By: cortinico

Differential Revision: D56467830

Pulled By: hick209

fbshipit-source-id: 0d97ccb01cfa8436443db27ec244a2759a57251d
  • Loading branch information
nreid260 authored and facebook-github-bot committed Apr 23, 2024
1 parent 76487c0 commit 4211ac2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ object TrailingCommas {
}

when (element) {
is KtEnumEntry, // Only suggest on the KtClassBody container
is KtWhenEntry -> return
is KtParameterList -> {
if (element.parent is KtFunctionLiteral && element.parent.parent is KtLambdaExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,25 @@ class GoogleStyleFormatterKtTest {
formattingOptions = Formatter.GOOGLE_FORMAT,
deduceMaxWidth = true)

@Test
fun `trailing commas on multline enum entries`() =
assertFormatted(
"""
|enum class MultilineEntries {
| A(
| arg = 0, //
| arg = 0,
| ),
| /* Comment */
| B,
| C {
| fun foo() {}
| },
|}
|"""
.trimMargin(),
formattingOptions = Formatter.GOOGLE_FORMAT)

@Test
fun `trailing commas in enums`() {
val code =
Expand Down

0 comments on commit 4211ac2

Please sign in to comment.