-
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
Inconsistent fewerBraces
indentation
#3489
Comments
@soronpo since you saw the other thread, you should understand the reason, and the consistency behind it. since we must indent chained methods ( |
just noticed this. is this really what you see? different indentation for |
Yes, indeed this is what I see. So first we have this inconsistency, and I actually do not understand why there is a need for the double indent at all. In the original issue, there is this example: def test(): String =
Block:
2 + 2
.toString After formatting, this code should NOT have changed at all. |
unfortunately, this example makes |
You say that from a formatter perspective or compiler perspective? From compiler perspective what currently scalafmt generates is simply incorrect and fails to compile. From formatter perspective, I just don't agree with "always indented relative to the beginning of the expression", and I don't think it's a valid assumption under a |
don't you think that means there's a bug in the compiler or the documentation? the rule says (https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html) that it inserts outdent if the indent is strictly less than the previous indented region.
@tgodzik how do we clear that up with the core language experts?
Which is why the formatter has always been called "opinionated". |
Shouldn't this also fail (your example, but with braces around the def body): |
That's a good question. I think we need Odersky to participate in this discussion. I'll try to e-mail him. |
It turns out this one passes because the enclosing region is enclosed in braces so it does not count as an indentation region. On the other hand, code like this looks reasonable, and it's a shame to reject it: def foo(xs: List[Int]) =
xs.map: x =>
x + 1
.filter: x =>
x > 0 See scala/scala3#17056 for a possible fix. |
Configuration (required)
Please paste the contents of your
.scalafmt.conf
file here:Command-line parameters (required)
When I run scalafmt via CLI like this:
scalafmt a.scala
Steps
Given code like this:
Problem
Scalafmt formats code like this:
Expectation
I would like the formatted output to look like this (same as the input, in this case):
Workaround
None
Notes
I think that it's worth considering adding an
indent.fewerBracesSite
option that will control the indentation for fewer braces.The text was updated successfully, but these errors were encountered: