From 6489c56053a833ef10f4c9ab86e0974acceebc79 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:41:24 -0800 Subject: [PATCH 1/2] Formatting: upgrade to v3.8.6 --- .scalafmt.conf | 2 +- .../org/scalafmt/dynamic/DynamicSuite.scala | 84 ++++++------- .../CommunityIntellijScalaSuite.scala | 106 ++++++++-------- .../test/scala/org/scalafmt/CommentTest.scala | 102 +++++++-------- .../test/scala/org/scalafmt/RangeTest.scala | 24 ++-- .../test/scala/org/scalafmt/cli/CliTest.scala | 117 +++++++++--------- .../org/scalafmt/util/StyleMapTest.scala | 34 ++--- 7 files changed, 234 insertions(+), 235 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index a7a0f4c1ff..e9c61676f2 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version=3.8.5 +version=3.8.6 runner.dialect = scala213 project { git = true diff --git a/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala b/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala index b23f007a23..0fd1c765d5 100644 --- a/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala +++ b/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala @@ -217,15 +217,15 @@ class DynamicSuite extends FunSuite { check("missing-version")(f => f.assertMissingVersion()) check("excluded-file") { f => - val config = """| - |project.includeFilters = [ - | ".*Spec\\.scala$" - |] - |project.excludeFilters = [ - | "UserSpec\\.scala$" - |] - |""" - .stripMargin + val config = + """| + |project.includeFilters = [ + | ".*Spec\\.scala$" + |] + |project.excludeFilters = [ + | "UserSpec\\.scala$" + |] + |""".stripMargin def check(version: String): Unit = { f.setVersion(version, "scala211", config) f.assertNotIgnored("path/FooSpec.scala") @@ -237,15 +237,15 @@ class DynamicSuite extends FunSuite { } check("ignore-exclude-filters", _.withRespectProjectFilters(false)) { f => - val config = """| - |project.includeFilters = [ - | ".*Spec\\.scala$" - |] - |project.excludeFilters = [ - | "UserSpec\\.scala$" - |] - |""" - .stripMargin + val config = + """| + |project.includeFilters = [ + | ".*Spec\\.scala$" + |] + |project.excludeFilters = [ + | "UserSpec\\.scala$" + |] + |""".stripMargin def check(version: String): Unit = { f.setVersion(version, "scala211", config) f.assertNotIgnored("path/App.pm") @@ -422,30 +422,30 @@ class DynamicSuite extends FunSuite { checkExhaustive("continuation-indent-callSite-and-defnSite")(_ => "continuationIndent { callSite = 5, defnSite = 3 }", ) { (f, _) => - val original = """|class A { - | function1( - | argument1, - | "" - | ) - | - | def function2( - | argument1: Type1 - | ): ReturnType - |} - | """ - .stripMargin - val expected = """|class A { - | function1( - | argument1, - | "" - | ) - | - | def function2( - | argument1: Type1 - | ): ReturnType - |} - |""" - .stripMargin + val original = + """|class A { + | function1( + | argument1, + | "" + | ) + | + | def function2( + | argument1: Type1 + | ): ReturnType + |} + | """.stripMargin + val expected = + """|class A { + | function1( + | argument1, + | "" + | ) + | + | def function2( + | argument1: Type1 + | ): ReturnType + |} + |""".stripMargin f.assertFormat(original, expected) } diff --git a/scalafmt-tests-community/intellij/src/test/scala/org/scalafmt/community/intellij/CommunityIntellijScalaSuite.scala b/scalafmt-tests-community/intellij/src/test/scala/org/scalafmt/community/intellij/CommunityIntellijScalaSuite.scala index 4639259442..990e68efa0 100644 --- a/scalafmt-tests-community/intellij/src/test/scala/org/scalafmt/community/intellij/CommunityIntellijScalaSuite.scala +++ b/scalafmt-tests-community/intellij/src/test/scala/org/scalafmt/community/intellij/CommunityIntellijScalaSuite.scala @@ -21,31 +21,31 @@ class CommunityIntellijScala_2024_2_Suite dialects.Scala213, 3469, excluded = "glob:**/{testdata,testData,resources}/**" :: Nil, - fileOverride = """|{ - | "glob:**/sbt/sbt-impl/workspace-entities/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/structure-view/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/repl/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/tasty-reader/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/package-search-client/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/integration/textAnalysis/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/integration/features-trainer/**" { - | runner.dialect = scala33 - | } - |} - |""" - .stripMargin, + fileOverride = + """|{ + | "glob:**/sbt/sbt-impl/workspace-entities/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/structure-view/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/repl/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/tasty-reader/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/package-search-client/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/integration/textAnalysis/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/integration/features-trainer/**" { + | runner.dialect = scala33 + | } + |} + |""".stripMargin, ) } @@ -62,34 +62,34 @@ class CommunityIntellijScala_2024_3_Suite dialects.Scala213, 3475, excluded = "glob:**/{testdata,testData,resources}/**" :: Nil, - fileOverride = """|{ - | "glob:**/sbt/sbt-impl/workspace-entities/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/structure-view/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/repl/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/tasty-reader/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/package-search-client/**" { - | runner.dialect = scala33 - | } - | "glob:**/scalac-patches/scalac3-patches/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/integration/textAnalysis/**" { - | runner.dialect = scala33 - | } - | "glob:**/scala/integration/features-trainer/**" { - | runner.dialect = scala33 - | } - |} - |""" - .stripMargin, + fileOverride = + """|{ + | "glob:**/sbt/sbt-impl/workspace-entities/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/structure-view/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/repl/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/tasty-reader/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/package-search-client/**" { + | runner.dialect = scala33 + | } + | "glob:**/scalac-patches/scalac3-patches/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/integration/textAnalysis/**" { + | runner.dialect = scala33 + | } + | "glob:**/scala/integration/features-trainer/**" { + | runner.dialect = scala33 + | } + |} + |""".stripMargin, ) } diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/CommentTest.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/CommentTest.scala index bc4ed45c81..aaef6e03f5 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/CommentTest.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/CommentTest.scala @@ -32,23 +32,23 @@ class CommentTest extends FunSuite { |val y = 2 |} | """.stripMargin - val expected = """|object a { - | // inline comment - | /** - | * Y is cool - | */ - | /* - | * X is cool - | */ - | /* - | I have blank lines. - | - | Please preserve them. - | */ - | val y = 2 - |} - |""" - .stripMargin + val expected = + """|object a { + | // inline comment + | /** + | * Y is cool + | */ + | /* + | * X is cool + | */ + | /* + | I have blank lines. + | + | Please preserve them. + | */ + | val y = 2 + |} + |""".stripMargin val obtained = Scalafmt.format(original, javadocStyle).get assertNoDiff(obtained, expected) } @@ -72,23 +72,23 @@ class CommentTest extends FunSuite { |val y = 2 |} | """.stripMargin - val expected = """|object a { - | // inline comment - | /** - | * Y is cool - | */ - | /* - | * X is cool - | */ - | /* - | I have blank lines. - | - | Please preserve them. - | */ - | val y = 2 - |} - |""" - .stripMargin + val expected = + """|object a { + | // inline comment + | /** + | * Y is cool + | */ + | /* + | * X is cool + | */ + | /* + | I have blank lines. + | + | Please preserve them. + | */ + | val y = 2 + |} + |""".stripMargin val obtained = Scalafmt.format(original, javadocStyle).get assertNoDiff(obtained, expected) } @@ -112,23 +112,23 @@ class CommentTest extends FunSuite { |val y = 2 |} | """.stripMargin - val expected = """|object a { - | // inline comment - | /** - | * Y is cool - | */ - | /* - | * X is cool - | */ - | /* - | I have blank lines. - | - | Please preserve them. - | */ - | val y = 2 - |} - |""" - .stripMargin + val expected = + """|object a { + | // inline comment + | /** + | * Y is cool + | */ + | /* + | * X is cool + | */ + | /* + | I have blank lines. + | + | Please preserve them. + | */ + | val y = 2 + |} + |""".stripMargin val obtained = Scalafmt.format(original, javadocStyle).get assertNoDiff(obtained, expected) } diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/RangeTest.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/RangeTest.scala index e414de4834..20df39979b 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/RangeTest.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/RangeTest.scala @@ -6,18 +6,18 @@ import munit.FunSuite class RangeTest extends FunSuite { test("range preserves indent") { - val original = """|object a { - |val x = 1 - |val y = 2 - |} - | """ - .stripMargin - val expected = """|object a { - |val x = 1 - | val y = 2 - |} - | """ - .stripMargin + val original = + """|object a { + |val x = 1 + |val y = 2 + |} + | """.stripMargin + val expected = + """|object a { + |val x = 1 + | val y = 2 + |} + | """.stripMargin val obtained = Scalafmt .format(original, HasTests.unitTest40, range = Set(Range(2, 2).inclusive)) .get diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala index a0149f8299..c854854313 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala @@ -47,41 +47,41 @@ abstract class AbstractCliTest extends FunSuite { out + "\n should have contained \n" + expected, ) - val unformatted = """| - |object a extends App { - |pr("h") - |} - | """ - .stripMargin + val unformatted = + """| + |object a extends App { + |pr("h") + |} + | """.stripMargin // Using maxColumn 10 just to see the CLI uses the custom style. - val expected10 = """|object a - | extends App { - | pr( - | "h" - | ) - |} - |""" - .stripMargin - val formatted = """|object a extends App { - | pr("h") - |} - |""" - .stripMargin - val customConfig = """| - |maxColumn = 2 - | """ - .stripMargin - val sbtOriginal = """|lazy val x = project - | lazy val y = project - | """ - .stripMargin - - val sbtExpected = """|lazy val x = - | project - |lazy val y = - | project - |""" - .stripMargin + val expected10 = + """|object a + | extends App { + | pr( + | "h" + | ) + |} + |""".stripMargin + val formatted = + """|object a extends App { + | pr("h") + |} + |""".stripMargin + val customConfig = + """| + |maxColumn = 2 + | """.stripMargin + val sbtOriginal = + """|lazy val x = project + | lazy val y = project + | """.stripMargin + + val sbtExpected = + """|lazy val x = + | project + |lazy val y = + | project + |""".stripMargin def gimmeConfig(string: String): ScalafmtConfig = ScalafmtConfig .fromHoconString(string).get @@ -400,12 +400,12 @@ trait CliTestBehavior { test(s"config is read even from nested dir: $label") { val original = "object a { val x = 1 }" - val expected = """|object a { - | val x = - | 1 - |} - |""" - .stripMargin + val expected = + """|object a { + | val x = + | 1 + |} + |""".stripMargin val input = string2dir( s"""|/nested/foo.scala |$original @@ -447,10 +447,10 @@ trait CliTestBehavior { assertNoDiff(dir2string(root / "sbt.sbtfile"), sbtOriginal) assertNoDiff(dir2string(root / "scalafile.scala"), formatted) - val sbtFormatted = """|lazy val x = project - |lazy val y = project - |""" - .stripMargin + val sbtFormatted = + """|lazy val x = project + |lazy val y = project + |""".stripMargin assertNoDiff(dir2string(root / "sbt.sbt"), sbtFormatted) } @@ -555,10 +555,10 @@ trait CliTestBehavior { } test(s"parse error is formatted nicely: $label") { - val input = """|/foo.scala - |object A { foo( } - |""" - .stripMargin + val input = + """|/foo.scala + |object A { foo( } + |""".stripMargin noArgTest( string2dir(input), input, @@ -615,10 +615,10 @@ trait CliTestBehavior { } test(s"--test succeeds even with parse error: $label") { - val input = """|/foo.scala - |object A { - |""" - .stripMargin + val input = + """|/foo.scala + |object A { + |""".stripMargin noArgTest( string2dir(input), input, @@ -794,8 +794,7 @@ class CliTest extends AbstractCliTest with CliTestBehavior { """|Illegal regex in configuration: .*foo( |reason: Unclosed group near index 6 |.*foo( - |""" - .stripMargin, + |""".stripMargin, ), Some(ExitCode.UnexpectedError), ) @@ -1241,11 +1240,11 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test("no final EOL") { val out = new ByteArrayOutputStream() val err = new ByteArrayOutputStream() - val codeNoEol = """|object FormatMe { - | val x = - | 1 - |}""" - .stripMargin + val codeNoEol = + """|object FormatMe { + | val x = + | 1 + |}""".stripMargin Console.withOut(out)(Console.withErr(err) { val options = getConfig(Array("--stdin", "--test")) val options2 = options.copy( diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/StyleMapTest.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/StyleMapTest.scala index cec6eae685..77e1058102 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/StyleMapTest.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/StyleMapTest.scala @@ -11,12 +11,13 @@ import munit.FunSuite class StyleMapTest extends FunSuite { test("basic") { - val code = """|object a { - | // scalafmt: { maxColumn = 100 } - | println(1) - | // scalafmt: { maxColumn = 110 } - |} - | """.stripMargin.parse[Source].get + val code = + """|object a { + | // scalafmt: { maxColumn = 100 } + | println(1) + | // scalafmt: { maxColumn = 110 } + |} + | """.stripMargin.parse[Source].get val m = new FormatOps(code, ScalafmtConfig.default) assertEquals( m.styleMap.at(m.tokens.head).maxColumn, @@ -35,8 +36,7 @@ class StyleMapTest extends FunSuite { | // scalafmt: { align.tokens."+" = [{ code="=", owner=".*" }] } | println(1) |} - | """ - .stripMargin.parse[Source].get + | """.stripMargin.parse[Source].get val formatOps = new FormatOps(code, ScalafmtConfig.defaultWithAlign) val headToken = formatOps.tokens.head val printlnToken = formatOps.tokens.find(_.left.syntax == "println").get @@ -75,8 +75,7 @@ class StyleMapTest extends FunSuite { | // scalafmt: { newlines.implicitParamListModifierForce = [after] } | println(1) |} - |""" - .stripMargin.parse[Source].get + |""".stripMargin.parse[Source].get val formatOps = new FormatOps( code, ScalafmtConfig(newlines = @@ -118,13 +117,14 @@ class StyleMapTest extends FunSuite { * One test uses the default settings (meaning, unsafeCallSite=false) while * the other starts with BinPack.enabled, which includes unsafeCallSite=true. */ - val code = """|object a { - | println(1, 2, 3, 4, 5, 6) - | println(1, 2, 3, 4, 5, 6) - | // scalafmt: { binPack.unsafeCallSite = false } - | println(1, 2, 3, 4, 5, 6) - |} - | """.stripMargin.parse[Source].get + val code = + """|object a { + | println(1, 2, 3, 4, 5, 6) + | println(1, 2, 3, 4, 5, 6) + | // scalafmt: { binPack.unsafeCallSite = false } + | println(1, 2, 3, 4, 5, 6) + |} + | """.stripMargin.parse[Source].get val fops1 = new FormatOps(code, ScalafmtConfig.default) val fops2 = new FormatOps(code, ScalafmtConfig(binPack = BinPack.always)) /* From af387931d8d5092f75bfed3ba309b17c2389fe5e Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:43:05 -0800 Subject: [PATCH 2/2] git blame: ignore scalafmt-3.8.6 reformat commits --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 4fbf9669a6..42751a7e20 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -18,3 +18,5 @@ d0be16274e954a83074244df3e7f2fe35be92ac1 3b7b5616443ede7e3fe3bd9fa316a06e266c2a9b da8534d89378be7d9b1db4032195abfea73e9619 b713da2d0fcee76fd27f6d2e6dbfacb15e2a1150 +# v3.8.6 +6489c56053a833ef10f4c9ab86e0974acceebc79