-
Notifications
You must be signed in to change notification settings - Fork 68
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
Closing parentheses placement for method calls does not match Kotlin style guide #29
Comments
Another related question is what to do about chained method calls if there's a line break before Having a line break and continuation indent after foo(
bar,
).baz(
bork,
) |
This is the existing formatting:
Which one do we prefer? First option wastes vertical space:
Second option looks weird:
I don't like either of the options, but the first one seems more sane. EDIT: For method parameters, we use the latter. @cushon, @strulovich, what says you? |
In any case, for a trailing comma we will do:
But I'd prefer keeping it for now as:
I'm against wasting vertical space. So if all args fit in one line I would keep them there. Is any of these a deal breaker for anyone? |
Do you mean we output different formatting based on whether a trailing comma exists? |
As long as we don't adjust the actual tokens (which for now we are not) I think that would be ok. |
Doing round on some old issues today. I prefer same line if if there's no trailing comma, and next line if there is one. We do not add or remove commas for now. @cushon, how does that sound to you? |
My vote is a new line, wasting the vertical space. IMO the consistency is what I value. |
At Google, we are using the first option (all parameters on separate lines, closing parens on its own line). This is also the style that ktlint enforces (all parameters must be on separate lines, unless they can all fit on the same line as the function name). The closing parens being on its own line is also key to having no continuation indents, as recommended by both Intellij and Android style guides. (See also discussion at #14 ) |
I like the approach of trailing lambdas to force multiline params even if it fits in one line. But I would like to force in a builder pattern to use multiline even if it fits in one line because of readability. The only approach now is this?
|
@JavierSegoviaCordoba I'm hesitant to introduce special formatting cases such as builder patterns. First, because I'm concerned it'll complicate the code and make it less maintainable, and second because it might be difficult to correctly identify the pattern. |
Closing this as it's an old issue and we currently by using trailing commas the closing parenthesis will wrap as suggested in the beginning of this discussion |
This came up in #10, but IIUC the changes made in that issue were only for method declarations, not method calls.
See e.g. https://kotlinlang.org/docs/reference/coding-conventions.html#method-call-formatting:
One reason this might be worth reconsidering is the support for trailing commas that was added in Kotlin 1.4 (see KT-9476), which will allow writing:
Leaving the closing paren
)
on the previous line seems like bad style:The text was updated successfully, but these errors were encountered: