-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.52 and trailing commas behavior on Kotlinlang formatting #512
Comments
Looks like this is intentional, going by the comments in the code
(Btw. that comment seems to have a mistake. I guess it should say, "Lists that fit on one line will have them removed.") ktfmt/core/src/main/java/com/facebook/ktfmt/format/TrailingCommas.kt Lines 64 to 78 in cec9b50
Personally, I would also prefer if anything with two arguments would be formatted on multiple lines with trailing commas. Edit: after using 0.52 a bit, I feel strongly that more than one argument should go on separate lines. The whole point of trailing commas is to make merge conflicts easier, isn't it? That should not depend on whether it fits on one line. |
I rolled back to even We had this: class RealSettingsWorkflow @Inject constructor(
private val oAuthTokenService: OAuthTokenService,
@UserId private val userId: String,
@VersionName private val versionName: String,
) : StatefulWorkflow<Unit, SettingsState, RootOutput, BodyAndOverlaysScreen<Screen, Overlay>>() { is now: class RealSettingsWorkflow
@Inject
constructor(
private val oAuthTokenService: OAuthTokenService,
@UserId private val userId: String,
@VersionName private val versionName: String,
) :
StatefulWorkflow<Unit, SettingsState, RootOutput, BodyAndOverlaysScreen<Screen, Overlay>>() { I am using |
Trailing comma management was initially flag guarded behind --google-style. The point of the feature is to enforce consistency, by removing the ability for devs to hint at formatting preference. Any proposal to change the behaviour needs to maintain that property for --google-style. The specific rules on when to remove/insert were designed-by-committee based on vibes. Keeping short lists to one line is broadly a choice to reduce vertical space (but we're absolutely not trying to minimize vertical space). In our experience, lots of people hated the new behaviour the first few times it rearranged their existing code. Then about two weeks later they got used to it, and went on with writing code. We also don't want to experience that pain more times than necessary, so there's a strong bias toward keeping the existing arbitrary rules, unless there's some, more objective, better approach. |
Discussed in #510
Originally posted by JavierSegoviaCordoba August 20, 2024
After upgrading I am seeing trailing commas being removed and I think it is not only worse because it is less flexible in terms of how you can format the code (decide to have multiline or not by adding a trailing comma), but objectively it can modify the code in a way it transforms something from multiline to single-line and vice-versa making the code reviews harder when you want to keep a multiline for readability reason and it becomes a single-line, and in a future when a new parameter is added it becomes again multiline.
That becomes:
And if you add more params:
The format on
constructor
has changed too, personally, I prefer the old one, which follows the "square" pattern:The text was updated successfully, but these errors were encountered: