From 9cfa893dc19d22220d740838a77c5f19ff4523ec Mon Sep 17 00:00:00 2001 From: Albert Meltzer Date: Wed, 20 Nov 2019 16:59:22 -0800 Subject: [PATCH 1/2] ScalafmtConfig: create an edition flag for 2019-11 --- .../main/scala/org/scalafmt/config/ScalafmtConfig.scala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ScalafmtConfig.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ScalafmtConfig.scala index 2dc438f91e..906893da57 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ScalafmtConfig.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ScalafmtConfig.scala @@ -192,6 +192,13 @@ case class ScalafmtConfig( continuationIndent.callSite, continuationIndent.defnSite ) + + // Edition-specific settings below + 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 { From 128fdeb3d419a486eeaa579635faf793a8794394 Mon Sep 17 00:00:00 2001 From: Albert Meltzer Date: Sat, 9 Nov 2019 09:48:45 -0800 Subject: [PATCH 2/2] RedundantBraces: remove nested braces in lambda --- .../scalafmt/rewrite/RedundantBraces.scala | 4 ++ .../resources/rewrite/RedundantBraces.stat | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala index c8b52d9ce7..148cd3e5fd 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala @@ -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 && diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat index 897c52ffd4..ecbcfe4eba 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat @@ -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 + }) +}