-
Notifications
You must be signed in to change notification settings - Fork 277
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
How to set blanks after class/object header/end ? #2888
Comments
доводилось ли почитать это: https://scalameta.org/scalafmt/docs/configuration.html#newlinestoplevelstatementblanklines |
Thanks for the link! I was thinking to make a regex to narrow the search, but I don't think it will work due to following: Would it be asking to match to point out how to overcome the shortcomings posted above? I am trying to make //somefile.scala
object A {
val a = 0
val b = 1
}
object B {
object C {
val a = 0
val b = 1
}
} to look like //somefile.scala
object A { // no blank after header
val a = 0
// max 1 blank between statements within the body
val b = 1
} // no blanks before closing brace
// max 1 blank between statements on source-level
object B { // no blank after header
object C { // no blank after header
val a = 0
// blank between statements within the body is left intact
val b = 1
} // no blanks before closing brace
} // no blanks before closing brace
Would you consider reopening the issue if you agree that there is no way to configure such formatting with the current functionality of Thnx! |
I can add
Via If you didn't care about nesting constraints, what you want can be accomplished via this:
Otherwise, the only thing that stands in your way is a bug in how nesting is computed (which I will fix shortly). Keep in mind that scalafmt will always predictably set the number of blanks. If a rule matches (and rules do not care about the existing number of blanks), it will dictate the number. If no rules match, the number of blanks will be no more than 1 (depending on whether there were any blanks to begin with). Therefore, you can't allow a user the flexibility of controlling the number of blanks in some range. |
@kitbellew This is amazing! |
Hi!
I am trying to make scalafmt to control the blanks after opening braces and before closing braces (more specifically - remove blanks over the limit) for classes/objects/traits/methods.
In IntelliJ IDEA formatting settings there is a family of settings called
keep maximum blank lines
andminimum blank lines
(with options such asafter class header
andbefore class end
).To extend of my knowledge it is not possible to control blanks before/after curly braces with current feature set of scalafmt, would you kindly consider adding such functionality?
Many thanks in advance for all the help!
Steps
Given code like this:
When I run scalafmt like this:
Problem
Scalafmt formats code like this:
Expectation
I would like the formatted output to look like this:
Workaround
The closest I have found to the solution is this but it is not possible to have
0
blank lines. On top of that it also inserts blanks between all top level statements of the class. And I need to modify only blanks after opening brace and before closing brace of the class/trait/objectNotes
The text was updated successfully, but these errors were encountered: