From 39923413bd04f6fa89f98a60418c9744bc75b6db Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 23 Dec 2023 20:32:22 -0800 Subject: [PATCH 1/2] RewriteScala3Settings: add granular syntax flags --- docs/configuration.md | 13 +++++- .../config/RewriteScala3Settings.scala | 26 +++++++++++- .../test/resources/scala3/OptionalBraces.stat | 37 +++++++++++++--- .../resources/scala3/OptionalBraces_fold.stat | 37 +++++++++++++--- .../resources/scala3/OptionalBraces_keep.stat | 40 +++++++++++++++--- .../scala3/OptionalBraces_unfold.stat | 42 ++++++++++++++++--- 6 files changed, 169 insertions(+), 26 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index c760066878..48e17a6feb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3605,18 +3605,29 @@ This section describes rules which are applied if the appropriate dialect (e.g., ### `rewrite.scala3.convertToNewSyntax` -If this flag is enabled, the following new syntax will be applied: +If this flag is enabled, the following new syntax will be applied (also, +**since 3.8.0**, if an appropriate flag under `rewrite.scala.newSyntax` is not +set to `false`, see below): - [control syntax](https://dotty.epfl.ch/docs/reference/other-new-features/control-syntax.html) - if dialect sets `allowSignificantIndentation` + (any scala3 dialect) and `...newSyntax.control` is set + - `if (...)` to `if ... then` + - `while (...)` to `while ... do` + - `for (...)` to `for ... do` (or `for (...) yield` to `for ... yield`) - [vararg splices](https://dotty.epfl.ch/docs/reference/changed-features/vararg-splices.html) - vararg `: _*` or `@ _*` to `*` if dialect sets `allowPostfixStarVarargSplices` + (any scala3, or scala2xxSource3) and `...newSyntax.deprecated` is set - [imports](https://dotty.epfl.ch/docs/reference/changed-features/imports.html) - import wildcard `_` to `*` if dialect sets `allowStarWildcardImport` + (any scala3, or scala2xxSource3) and `...newSyntax.deprecated` is set - import rename `=>` to `as` if dialect sets `allowAsForImportRename` + (any scala3, or scala2xxSource3) and `...newSyntax.deprecated` is set - [wildcards](https://docs.scala-lang.org/scala3/reference/changed-features/wildcards.html) - type wildcard `_` to `?` if dialect sets `allowQuestionMarkAsTypeWildcard` + (scala212 and later) and `...newSyntax.deprecated` is set - anonymous type param `*` to `_` if dialect sets `allowUnderscoreAsTypePlaceholder` + (scala3Future only) and `...newSyntax.deprecated` is set NB: You could control these rules individually by [overriding dialect properties](#runnerdialectoverride). diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/RewriteScala3Settings.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/RewriteScala3Settings.scala index 75ec72a4e1..15bd0649fb 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/RewriteScala3Settings.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/RewriteScala3Settings.scala @@ -6,6 +6,7 @@ import metaconfig._ case class RewriteScala3Settings( convertToNewSyntax: Boolean = false, + newSyntax: ConvertToNewSyntax = ConvertToNewSyntax.default, removeOptionalBraces: RemoveOptionalBraces = RemoveOptionalBraces.no, countEndMarkerLines: RewriteScala3Settings.EndMarkerLines = RewriteScala3Settings.EndMarkerLines.all, @@ -24,7 +25,10 @@ object RewriteScala3Settings { implicit val decodec: ConfDecoderEx[RewriteScala3Settings] = Presets .mapDecoder(generic.deriveDecoderEx(default).noTypos, "rewrite.scala3") { case Conf.Bool(true) => - new RewriteScala3Settings(true, RemoveOptionalBraces.yes) + new RewriteScala3Settings( + convertToNewSyntax = true, + removeOptionalBraces = RemoveOptionalBraces.yes + ) case Conf.Bool(false) => default } @@ -56,4 +60,24 @@ object RewriteScala3Settings { } + case class ConvertToNewSyntax( + // https://dotty.epfl.ch/docs/reference/other-new-features/control-syntax.html + control: Boolean = true, + // https://dotty.epfl.ch/docs/reference/changed-features/vararg-splices.html + // https://dotty.epfl.ch/docs/reference/changed-features/imports.html + // https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html + deprecated: Boolean = true + ) + + private object ConvertToNewSyntax { + + val default = new ConvertToNewSyntax + + implicit val surface: generic.Surface[ConvertToNewSyntax] = + generic.deriveSurface + implicit val codec: ConfCodecEx[ConvertToNewSyntax] = + generic.deriveCodecEx(default).noTypos + + } + } diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat index 1579630790..9eeb602ee0 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat @@ -1206,8 +1206,8 @@ rewrite.scala3.removeOptionalBraces = yes === object a { val a = { - if (a) { // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } + if (a) { // scalafmt: { rewrite.scala3.newSyntax.control = false } + if (aa) { // scalafmt: { rewrite.scala3.newSyntax.control = true } aaa } // c1 } else { @@ -1234,10 +1234,10 @@ object a { >>> object a: val a = - if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } - aaa - } // c1 + if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } + if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa + // c1 else b val a = if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } @@ -1270,11 +1270,25 @@ object a { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while (a > 0) { + while (a > 0) do { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for (a <- b) { for (a <- b) do { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for (a <- b) do { + for (a <- b) { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for {a <- b} { for {a <- b} do { foo @@ -1285,8 +1299,15 @@ object a { object a: for (a <- b) yield for a <- b yield foo while a > 0 do while a > 0 do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while a > 0 do while a > 0 do foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } for a <- b do for a <- b do foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } + for a <- b do for a <- b do foo +end a <<< rewrite to new syntax with for-do, multiple runner.parser = source rewrite.scala3.insertEndMarkerMinLines = 6 @@ -1381,6 +1402,8 @@ object a: import scala.{annotation => ann} import java as j import Predef.{augmentString => _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString => _} >>> object a: import A.{min as minimum, `*` as multiply} @@ -1388,6 +1411,8 @@ object a: import scala.{annotation as ann} import java as j import Predef.{augmentString as _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString as _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat index 8d12387704..166ad4062a 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat @@ -1133,8 +1133,8 @@ rewrite.scala3.removeOptionalBraces = yes === object a { val a = { - if (a) { // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } + if (a) { // scalafmt: { rewrite.scala3.newSyntax.control = false } + if (aa) { // scalafmt: { rewrite.scala3.newSyntax.control = true } aaa } // c1 } else { @@ -1161,10 +1161,10 @@ object a { >>> object a: val a = - if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } - aaa - } // c1 + if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } + if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa + // c1 else b val a = if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } @@ -1197,11 +1197,25 @@ object a { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while (a > 0) { + while (a > 0) do { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for (a <- b) { for (a <- b) do { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for (a <- b) do { + for (a <- b) { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for {a <- b} { for {a <- b} do { foo @@ -1212,8 +1226,15 @@ object a { object a: for (a <- b) yield for a <- b yield foo while a > 0 do while a > 0 do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while a > 0 do while a > 0 do foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } for a <- b do for a <- b do foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } + for a <- b do for a <- b do foo +end a <<< rewrite to new syntax with for-do, multiple runner.parser = source rewrite.scala3.insertEndMarkerMinLines = 6 @@ -1308,6 +1329,8 @@ object a: import scala.{annotation => ann} import java as j import Predef.{augmentString => _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString => _} >>> object a: import A.{min as minimum, `*` as multiply} @@ -1315,6 +1338,8 @@ object a: import scala.{annotation as ann} import java as j import Predef.{augmentString as _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString as _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat index c106691b8f..82c85ffe06 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat @@ -1213,8 +1213,8 @@ rewrite.scala3.removeOptionalBraces = yes === object a { val a = { - if (a) { // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } + if (a) { // scalafmt: { rewrite.scala3.newSyntax.control = false } + if (aa) { // scalafmt: { rewrite.scala3.newSyntax.control = true } aaa } // c1 } else { @@ -1241,10 +1241,10 @@ object a { >>> object a: val a = - if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } - aaa - } // c1 + if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } + if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa + // c1 else b val a = @@ -1282,11 +1282,25 @@ object a { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while (a > 0) { + while (a > 0) do { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for (a <- b) { for (a <- b) do { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for (a <- b) do { + for (a <- b) { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for {a <- b} { for {a <- b} do { foo @@ -1299,9 +1313,19 @@ object a: while a > 0 do while a > 0 do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while a > 0 do + while a > 0 do + foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for a <- b do + for a <- b do + foo + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo @@ -1400,6 +1424,8 @@ object a: import scala.{annotation => ann} import java as j import Predef.{augmentString => _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString => _} >>> object a: import A.{min as minimum, `*` as multiply} @@ -1407,6 +1433,8 @@ object a: import scala.{annotation as ann} import java as j import Predef.{augmentString as _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString as _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat index 06519806f1..154de34fe3 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -1292,8 +1292,8 @@ rewrite.scala3.removeOptionalBraces = yes === object a { val a = { - if (a) { // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } + if (a) { // scalafmt: { rewrite.scala3.newSyntax.control = false } + if (aa) { // scalafmt: { rewrite.scala3.newSyntax.control = true } aaa } // c1 } else { @@ -1320,10 +1320,10 @@ object a { >>> object a: val a = - if a then // scalafmt: { rewrite.scala3.convertToNewSyntax = false } - if (aa) { // scalafmt: { rewrite.scala3.convertToNewSyntax = true } - aaa - } // c1 + if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } + if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa + // c1 else b val a = @@ -1361,11 +1361,25 @@ object a { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while (a > 0) { + while (a > 0) do { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for (a <- b) { for (a <- b) do { foo } } + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for (a <- b) do { + for (a <- b) { + foo + } + } + // scalafmt: { rewrite.scala3.newSyntax.control = true } for {a <- b} { for {a <- b} do { foo @@ -1381,10 +1395,22 @@ object a: while a > 0 do foo end while + // scalafmt: { rewrite.scala3.newSyntax.control = false } + while a > 0 do + while a > 0 do + foo + end while + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo end for + // scalafmt: { rewrite.scala3.newSyntax.control = false } + for a <- b do + for a <- b do + foo + end for + // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo @@ -1518,6 +1544,8 @@ object a: import scala.{annotation => ann} import java as j import Predef.{augmentString => _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString => _} >>> object a: import A.{min as minimum, `*` as multiply} @@ -1525,6 +1553,8 @@ object a: import scala.{annotation as ann} import java as j import Predef.{augmentString as _} + // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } + import Predef.{augmentString as _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes From 30aa8850dbf0843d466301c37949f5f922e4b73d Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:49:22 -0800 Subject: [PATCH 2/2] ConvertToNewScala3Syntax: use the new parameter --- .../rewrite/ConvertToNewScala3Syntax.scala | 33 +++++++++++-------- .../test/resources/scala3/OptionalBraces.stat | 13 +++++--- .../resources/scala3/OptionalBraces_fold.stat | 10 +++--- .../resources/scala3/OptionalBraces_keep.stat | 18 +++++----- .../scala3/OptionalBraces_unfold.stat | 18 +++++----- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ConvertToNewScala3Syntax.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ConvertToNewScala3Syntax.scala index b3ff3f24bb..ac78ce659c 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ConvertToNewScala3Syntax.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ConvertToNewScala3Syntax.scala @@ -32,38 +32,41 @@ private class ConvertToNewScala3Syntax(ftoks: FormatTokens) ft: FormatToken, style: ScalafmtConfig ): Option[Replacement] = Option { + val flag = style.rewrite.scala3.newSyntax + def left = ftoks.prevNonComment(ft).left ft.right match { - case _: Token.LeftParen if dialect.allowSignificantIndentation => + case _: Token.LeftParen + if flag.control && dialect.allowSignificantIndentation => ft.meta.rightOwner match { - case _: Term.If if ftoks.prevNonComment(ft).left.is[Token.KwIf] => + case _: Term.If if left.is[Token.KwIf] => removeToken - case _: Term.While - if ftoks.prevNonComment(ft).left.is[Token.KwWhile] => + case _: Term.While if left.is[Token.KwWhile] => removeToken - case _: Term.For if ftoks.prevNonComment(ft).left.is[Token.KwFor] => + case _: Term.For if left.is[Token.KwFor] => removeToken - case _: Term.ForYield - if ftoks.prevNonComment(ft).left.is[Token.KwFor] => + case _: Term.ForYield if left.is[Token.KwFor] => removeToken case _ => null } - case _: Token.Colon if dialect.allowPostfixStarVarargSplices => + case _: Token.Colon + if flag.deprecated && dialect.allowPostfixStarVarargSplices => ft.meta.rightOwner match { case t: Term.Repeated if isSimpleRepeated(t) => removeToken // trick: to get "*", just remove ":" and "_" case _ => null } - case _: Token.At if dialect.allowPostfixStarVarargSplices => + case _: Token.At + if flag.deprecated && dialect.allowPostfixStarVarargSplices => ft.meta.rightOwner match { case Pat.Bind(_, _: Pat.SeqWildcard) => removeToken // trick: to get "*", just remove "@" and "_" case _ => null } - case _: Token.Underscore => + case _: Token.Underscore if flag.deprecated => ft.meta.rightOwner match { case _: Importee.Wildcard if dialect.allowStarWildcardImport => replaceTokenIdent("*", ft.right) @@ -81,14 +84,15 @@ private class ConvertToNewScala3Syntax(ftoks: FormatTokens) case _ => null } - case _: Token.RightArrow if dialect.allowAsForImportRename => + case _: Token.RightArrow + if flag.deprecated && dialect.allowAsForImportRename => ft.meta.rightOwner match { case _: Importee.Rename | _: Importee.Unimport => replaceTokenIdent("as", ft.right) case _ => null } - case Token.Ident("*") => + case Token.Ident("*") if flag.deprecated => ft.meta.rightOwner match { case _: Type.AnonymousParam if dialect.allowUnderscoreAsTypePlaceholder => @@ -106,18 +110,19 @@ private class ConvertToNewScala3Syntax(ftoks: FormatTokens) ft: FormatToken, style: ScalafmtConfig ): Option[(Replacement, Replacement)] = Option { + def nextRight = ftoks.nextNonComment(ftoks.next(ft)).right ft.right match { case x: Token.RightParen if left.how eq ReplacementType.Remove => ft.meta.rightOwner match { case _: Term.If => - if (!ftoks.nextNonComment(ftoks.next(ft)).right.is[Token.KwThen]) + if (!nextRight.is[Token.KwThen]) replaceToken("then")( new Token.KwThen(x.input, x.dialect, x.start) ) else removeToken case _: Term.While | _: Term.For => - if (!ftoks.nextNonComment(ftoks.next(ft)).right.is[Token.KwDo]) + if (!nextRight.is[Token.KwDo]) replaceToken("do")(new Token.KwDo(x.input, x.dialect, x.start)) else removeToken case _ => null diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat index 9eeb602ee0..d6933d6fc7 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat @@ -1235,8 +1235,8 @@ object a { object a: val a = if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } - if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } - aaa + if (aa) // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa // c1 else b val a = @@ -1300,11 +1300,14 @@ object a: for (a <- b) yield for a <- b yield foo while a > 0 do while a > 0 do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - while a > 0 do while a > 0 do foo + while (a > 0) + while a > 0 do foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - for a <- b do for a <- b do foo + for (a <- b) do + for (a <- b) + foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo end a @@ -1412,7 +1415,7 @@ object a: import java as j import Predef.{augmentString as _} // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } - import Predef.{augmentString as _} + import Predef.{augmentString => _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat index 166ad4062a..00e0324847 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat @@ -1162,8 +1162,8 @@ object a { object a: val a = if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } - if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } - aaa + if (aa) // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa // c1 else b val a = @@ -1227,11 +1227,11 @@ object a: for (a <- b) yield for a <- b yield foo while a > 0 do while a > 0 do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - while a > 0 do while a > 0 do foo + while (a > 0) while a > 0 do foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - for a <- b do for a <- b do foo + for (a <- b) do for (a <- b) foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo end a @@ -1339,7 +1339,7 @@ object a: import java as j import Predef.{augmentString as _} // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } - import Predef.{augmentString as _} + import Predef.{augmentString => _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat index 82c85ffe06..5fee9dd819 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat @@ -1242,8 +1242,8 @@ object a { object a: val a = if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } - if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } - aaa + if (aa) // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa // c1 else b @@ -1314,17 +1314,17 @@ object a: while a > 0 do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - while a > 0 do - while a > 0 do - foo + while (a > 0) + while a > 0 do + foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do foo // scalafmt: { rewrite.scala3.newSyntax.control = false } - for a <- b do - for a <- b do - foo + for (a <- b) do + for (a <- b) + foo // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do for a <- b do @@ -1434,7 +1434,7 @@ object a: import java as j import Predef.{augmentString as _} // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } - import Predef.{augmentString as _} + import Predef.{augmentString => _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat index 154de34fe3..6cf57d131e 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -1321,8 +1321,8 @@ object a { object a: val a = if a then // scalafmt: { rewrite.scala3.newSyntax.control = false } - if aa then // scalafmt: { rewrite.scala3.newSyntax.control = true } - aaa + if (aa) // scalafmt: { rewrite.scala3.newSyntax.control = true } + aaa // c1 else b @@ -1396,9 +1396,9 @@ object a: foo end while // scalafmt: { rewrite.scala3.newSyntax.control = false } - while a > 0 do - while a > 0 do - foo + while (a > 0) + while a > 0 do + foo end while // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do @@ -1406,9 +1406,9 @@ object a: foo end for // scalafmt: { rewrite.scala3.newSyntax.control = false } - for a <- b do - for a <- b do - foo + for (a <- b) do + for (a <- b) + foo end for // scalafmt: { rewrite.scala3.newSyntax.control = true } for a <- b do @@ -1554,7 +1554,7 @@ object a: import java as j import Predef.{augmentString as _} // scalafmt: { rewrite.scala3.newSyntax.deprecated = false } - import Predef.{augmentString as _} + import Predef.{augmentString => _} <<< rewrite to new syntax, imports, scala2-source3 rewrite.scala3.convertToNewSyntax = true rewrite.scala3.removeOptionalBraces = yes