Kotlin / Kotlin/ktfmt

Google style with trailing comma does not use maxWidth correctly

Open
#472 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
1.3k
Forks
116
Avg merge
4d 10h
Merged PRs (30d)
15

Description

Hello!

There seems to be an off-by-one error when using Google-style and trailing commas. I just tried out the Google Style with trailing commas and saw the following scenario:
```
@Test
fun testShowBillingErrorPaymentButton() =
composeExtension.use {
// Arrange
setContentWithTheme {
AccountScreen(
state =
AccountUiState.default()
.copy(billingPaymentState = PaymentState.Error.Billing),
uiSideEffect = MutableSharedFlow().asSharedFlow(),
)
}

// Assert
onNodeWithText("Add 30 days time").assertExists()
}

```
The line:
``` uiSideEffect = MutableSharedFlow().asSharedFlow(),```
ends up being 101 characters even though I set maxWidth to 100.

If i change the named parameter to `uiSideEffects`, we see the following behavior, where it correctly wraps the line:
```
@Test
fun testShowBillingErrorPaymentButton() =
composeExtension.use {
// Arrange
setContentWithTheme {
AccountScreen(
state =
AccountUiState.default()
.copy(billingPaymentState = PaymentState.Error.Billing),
uiSideEffects =
MutableSharedFlow().asSharedFlow(),
)
}

// Assert
onNodeWithText("Add 30 days time").assertExists()
}
```

My configuration is as follows:
```
configure {
googleStyle()
blockIndent.set(4)
continuationIndent.set(4)
maxWidth.set(100)
removeUnusedImports.set(true)
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the Kotlin reproducer and the ktfmt Gradle configuration in the issue, focusing on Google style, trailing commas, and maxWidth handling. Compare formatting with the uiSideEffect and uiSideEffects parameter names; done means the formatter keeps the configured 100-character limit in both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.