Skip to content
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

RedundantBraces: remove nested braces in lambda #1549

Merged
merged 2 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ case class ScalafmtConfig(
continuationIndent.callSite,
continuationIndent.defnSite
)

// Edition-specific settings below
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to keep predefined edition flags (rather than comparing two editions for every token, as @olafurpg pointed out), it probably makes sense to put them here.

after we merge this, i will rebase #1551 as it uses editions as well.

def activeFor(edition: Edition): Boolean =
Edition.ordering.gteq(this.edition, edition)

// Edition 2019-11
val activeForEdition_2019_11: Boolean = activeFor(Edition(2019, 11))
}

object ScalafmtConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ case object RedundantBraces extends Rewrite {
!isProcedureSyntax(d) &&
!disqualifiedByUnit

case p: Term.Function
if ctx.style.activeForEdition_2019_11 && isBlockFunction(p) =>
settings.methodBodies

case _ =>
settings.generalExpressions &&
exactlyOneStatement &&
Expand Down
54 changes: 54 additions & 0 deletions scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,57 @@ object a {
def x: Int = // comment
2
}
<<< fixes nested block in multi-line lambda 1
object a {
method { x => { // 1
2
3
4
}
}
}
>>>
object a {
method { x => // 1
2
3
4
}
}
<<< fixes nested block in multi-line lambda 2
object a {
method { x =>
{ // 1
2
3
4
}
}
}
>>>
object a {
method { x =>
// 1
2
3
4
}
}
<<< doesn't touch block in multi-line paren lambda
object a {
method ( x =>
{
2
3
4
}
)
}
>>>
object a {
method(x => {
2
3
4
})
}