-
Notifications
You must be signed in to change notification settings - Fork 276
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
Router: handle if with/without braces consistently #1752
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I like it! But I would rather wait for the rest maintainers opinion because of large diffs in scala-repos
@olafurpg @tanishiking your thoughts on this change? the diffs in
to
for consistency with existing
|
Thanks! I'll take a look this evening :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for working on this @kitbellew 👍
IMO, I don't like this formatting result, and judging from the original scala-repos
coding styles, I guess there will be a backlash against this change, because a lot of codebases try to accommodate if statement to the same line with LHS.
To fix the inconsistency mentioned in #1747, I think it would me better to format like the following examples.
// 3
val ok3 = if (a > 10)
Some(a)
else
None
// to
val ko3 = if (a > 10)
Some(a)
else
None
(personally, it's best to "val ko3 = if (a > 10) Some(a) else None" in a single line)
// 4
val ok4 = if (a > 10) Some(a) else {
None
}
// to
val ok4 = if (a > 10)
Some(a)
else {
None
}
or something. (Personally I'm ok with the current scalafmt's behavior, and we don't necessarily change the current behavior if someone is REALLY want to change current behavior).
What do you think about this? @paulkore
Allow space if we can fit condition on the line (brings no-brace "then" in line with brace "then"), and require indent if there's an else part. Fixes scalameta#1747.
@tanishiking @poslegm PTAL, updated code with Rikito's suggestion, uploaded new diffs (mostly whitespace for indent, and some non-brace |
I don't sure that additional indent is the best solution for the consistency problem. Especially I don't like this: val x = if (x > max) "a"
else "b" Personally I prefer first version of @kitbellew's changes because it perfectly standardizes if/else formatting. But because of large diff in real-world codebases we may be forced to keep current "liberal" behavior 😞 |
Neither do I (including the brace version). Continuing without a break logically means that there's only one expression on the right, which works with a Abandon? Add a parameter similar to |
It really looks like a good case for |
should we simply reuse |
sounds reasonable |
Hi all, I'm glad to see that progress is being made on this issue! @tanishiking , to answer your question from before, I agree with you: However, I'm not sure about the indentation.
|
Thank you so much for modifying @kitbellew and your comment @paulkore IMO, we don't have to fix this "inconsistency" between if/else with and without braces. (I mean it's best to maintain the status quo). Though @paulkore mentioned that there's an inconsistency between those formatting results, I think we don't have to honor the consistency about the indent/newline between them, // without braces
val ok3 =
if (a > 10) Some(a)
else None
// with braces
val ok3 = if (a > 10) {
Some(a)
} else {
None
} That's why I believe it's better not to change the current behavior. It's ok with adding an option, but in that case, I think it's better to keep the default behavior. |
To do that, allow space only if 'else' is empty or the entire expression fits on the line.
Fixes #1747.
scala-repos
diffs: kitbellew/scala-repos@3670a38?w=1p.s. old diffs: kitbellew/scala-repos@dc650f9?w=1