diff --git a/.scalafmt.conf b/.scalafmt.conf index 53910824dc..377f9d702a 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.8.6" +version = "3.9.1" align.preset = more maxColumn = 100 diff --git a/DEV.md b/DEV.md index a4b0d6e961..1e11e908a1 100644 --- a/DEV.md +++ b/DEV.md @@ -192,8 +192,6 @@ Here's some of the more important external projects used by Scala CLI: [libsodium](https://github.com/jedisct1/libsodium), that is used by Scala CLI to encrypt secrets uploaded as GitHub repository secrets in the `publish setup` sub-command - [scala-cli-setup](https://github.com/VirtusLab/scala-cli-setup): a GitHub Action to install Scala CLI. -- [scalafmt-native-image](https://github.com/VirtusLab/scalafmt-native-image): GraalVM native-image launchers - for `scalafmt`. - [bloop-core](https://github.com/scala-cli/bloop-core): a fork of [bloop](https://github.com/scalacenter/bloop) stripped up of its benchmark infrastructure and build integrations. - [no-crc32-zip-input-stream](https://github.com/VirtusLab/no-crc32-zip-input-stream): A copy of `ZipInputStream` @@ -203,6 +201,10 @@ Here's some of the more important external projects used by Scala CLI: - [java-class-name](https://github.com/VirtusLab/java-class-name): a small library to extract class names from Java sources. +Legacy projects: +- [scalafmt-native-image](https://github.com/VirtusLab/scalafmt-native-image): GraalVM native-image launchers + for `scalafmt` (used for `scalafmt` versions < 3.9.1, no longer maintained) + The use of external binaries allows to make the Scala CLI binary slimmer and faster to generate, but also allow to lower memory requirements to generate it (allowing to generate these binaries on the GitHub-provided GitHub actions hosts). diff --git a/modules/cli/src/main/scala/scala/cli/commands/fmt/FmtOptions.scala b/modules/cli/src/main/scala/scala/cli/commands/fmt/FmtOptions.scala index b91629a3e5..3590a3e1af 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/fmt/FmtOptions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/fmt/FmtOptions.scala @@ -10,6 +10,7 @@ import scala.build.options.BuildOptions import scala.cli.ScalaCli.fullRunnerName import scala.cli.commands.shared.{HasSharedOptions, HelpGroup, HelpMessages, SharedOptions} import scala.cli.commands.{Constants, tags} +import scala.cli.coursierVersion import scala.util.Properties // format: off @@ -96,12 +97,18 @@ final case class FmtOptions( .getOrElse(FetchExternalBinary.platformSuffix()) val tag0 = scalafmtTag.getOrElse("v" + version) val gitHubOrgName0 = scalafmtGithubOrgName.getOrElse { - if (Version(version) < Version("3.5.9")) - "scala-cli/scalafmt-native-image" - else // from version 3.5.9 scalafmt-native-image repository was moved to VirtusLab organisation - "virtuslab/scalafmt-native-image" + version.coursierVersion match { + case v if v < "3.5.9".coursierVersion => "scala-cli/scalafmt-native-image" + // since version 3.5.9 scalafmt-native-image repository was moved to VirtusLab organisation + case v if v < "3.9.1".coursierVersion => "virtuslab/scalafmt-native-image" + // since version 3.9.1 native images for all platforms are provided by ScalaMeta + case _ => "scalameta/scalafmt" + } + } + val extension0 = version match { + case v if v.coursierVersion >= "3.9.1".coursierVersion || Properties.isWin => ".zip" + case _ => ".gz" } - val extension0 = if (Properties.isWin) ".zip" else ".gz" val url = s"https://github.com/$gitHubOrgName0/releases/download/$tag0/scalafmt-$osArchSuffix0$extension0" (url, !tag0.startsWith("v")) diff --git a/modules/cli/src/test/scala/cli/tests/ScalafmtTest.scala b/modules/cli/src/test/scala/cli/tests/ScalafmtTest.scala index 580709a523..9254f655ff 100644 --- a/modules/cli/src/test/scala/cli/tests/ScalafmtTest.scala +++ b/modules/cli/src/test/scala/cli/tests/ScalafmtTest.scala @@ -10,6 +10,7 @@ import scala.cli.commands.fmt.{FmtOptions, FmtUtil} import scala.cli.commands.update.Update.Release class ScalafmtTests extends munit.FunSuite { + private lazy val defaultScalafmtVersion = Constants.defaultScalafmtVersion test("readVersionFromFile with non-default scalafmt version") { val confFile = """runner.dialect = scala213 @@ -34,27 +35,25 @@ class ScalafmtTests extends munit.FunSuite { } } - test("check native launcher availability for scalafmt") { + test(s"check native launcher availability for scalafmt $defaultScalafmtVersion") { final case class Asset(name: String) final case class Release(tag_name: String, assets: List[Asset]) lazy val releaseCodec: JsonValueCodec[Release] = JsonCodecMaker.make - - val scalaFmtVersion = Constants.defaultScalafmtVersion val url = - s"https://api.github.com/repos/virtuslab/scalafmt-native-image/releases/tags/v$scalaFmtVersion" + s"https://api.github.com/repos/scalameta/scalafmt/releases/tags/v$defaultScalafmtVersion" val expectedAssets = Seq( - "scalafmt-x86_64-apple-darwin.gz", - "scalafmt-x86_64-pc-linux-mostly-static.gz", - "scalafmt-x86_64-pc-linux-static.gz", - "scalafmt-x86_64-pc-linux.gz", - "scalafmt-x86_64-pc-win32.zip" + "scalafmt-x86_64-apple-darwin.zip", + "scalafmt-x86_64-pc-linux.zip", + "scalafmt-x86_64-pc-win32.zip", + "scalafmt-aarch64-apple-darwin.zip", + "scalafmt-aarch64-pc-linux.zip" ) val errorMsg = - s"""scalafmt native images missing for v$scalaFmtVersion, make a release at https://github.com/VirtusLab/scalafmt-native-image + s"""scalafmt native images missing for v$defaultScalafmtVersion at https://github.com/scalameta/scalafmt |Ensure that all expected assets are available in the release: | ${expectedAssets.mkString(", ")} - |for scalafmt-native-image under tag v$scalaFmtVersion.""".stripMargin + |under tag v$defaultScalafmtVersion.""".stripMargin try { val resp = TestUtil.downloadFile(url).orThrow val release = readFromArray(resp)(releaseCodec) @@ -68,7 +67,7 @@ class ScalafmtTests extends munit.FunSuite { catch { case e: JsonReaderException => throw new Exception(s"Error reading $url", e) case e: Throwable => throw new Exception( - s"""Failed to check for the ScalaFmt native launcher assets: ${e.getMessage} + s"""Failed to check for the ScalaFmt $defaultScalafmtVersion native launcher assets: ${e.getMessage} | |$errorMsg |""".stripMargin, diff --git a/modules/integration/src/test/scala/scala/cli/integration/DependencyUpdateTests.scala b/modules/integration/src/test/scala/scala/cli/integration/DependencyUpdateTests.scala index 9ecf1b9ad4..3e7ab62ff7 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/DependencyUpdateTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/DependencyUpdateTests.scala @@ -25,7 +25,8 @@ class DependencyUpdateTests extends ScalaCliSuite { ) expect(p.out.trim().contains("Updated dependency")) expect( // check if dependency update command modify file - os.read(root / fileName) != fileContent) + os.read(root / fileName) != fileContent + ) // after updating dependencies app should run val out = os.proc(TestUtil.cli, fileName).call(cwd = root).out.trim() diff --git a/modules/integration/src/test/scala/scala/cli/integration/FmtTests.scala b/modules/integration/src/test/scala/scala/cli/integration/FmtTests.scala index fe1c05ed57..a4314d1a07 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/FmtTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/FmtTests.scala @@ -95,11 +95,8 @@ class FmtTests extends ScalaCliSuite { test("filter correctly with --check") { simpleInputsWithFilter.fromRoot { root => - val out = os.proc(TestUtil.cli, "fmt", ".", "--check").call(cwd = root).out.trim() - val outLines = out.linesIterator.toSeq - expect(outLines.length == 2) - expect(outLines.head == "Looking for unformatted files...") - expect(outLines.last == "All files are formatted with scalafmt :)") + val out = os.proc(TestUtil.cli, "fmt", ".", "--check").call(cwd = root).out.trim() + expect(out == "All files are formatted with scalafmt :)") } } diff --git a/project/deps.sc b/project/deps.sc index 3f6eee42f0..d6ac9fb8f9 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -118,6 +118,7 @@ object Deps { def jsoniterScalaJava8 = "2.13.5.2" def jsoup = "1.18.3" def scalaMeta = "4.13.2" + def scalafmt = "3.9.1" def scalaNative04 = "0.4.17" def scalaNative05 = "0.5.7" def scalaNative = scalaNative05 @@ -211,7 +212,7 @@ object Deps { def scala3Compiler(sv: String) = ivy"org.scala-lang:scala3-compiler_3:$sv" def scalaAsync = ivy"org.scala-lang.modules::scala-async:1.0.1".exclude("*" -> "*") def scalac(sv: String) = ivy"org.scala-lang:scala-compiler:$sv" - def scalafmtCli = ivy"org.scalameta:scalafmt-cli_2.13:3.8.6" + def scalafmtCli = ivy"org.scalameta:scalafmt-cli_2.13:${Versions.scalafmt}" // Force using of 2.13 - is there a better way? def scalaJsEnvJsdomNodejs = ivy"org.scala-js:scalajs-env-jsdom-nodejs_2.13:1.1.0" diff --git a/website/docs/reference/cli-options.md b/website/docs/reference/cli-options.md index 9cc700e393..1668359ef2 100644 --- a/website/docs/reference/cli-options.md +++ b/website/docs/reference/cli-options.md @@ -501,7 +501,7 @@ Pass a global dialect for scalafmt. This overrides whatever value is configured Aliases: `--fmt-version` -Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. +Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. ## Global suppress warning options diff --git a/website/docs/reference/scala-command/cli-options.md b/website/docs/reference/scala-command/cli-options.md index 274bd06097..48d1a5d231 100644 --- a/website/docs/reference/scala-command/cli-options.md +++ b/website/docs/reference/scala-command/cli-options.md @@ -370,7 +370,7 @@ Aliases: `--fmt-version` `IMPLEMENTATION specific` per Scala Runner specification -Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. +Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. ## Global suppress warning options diff --git a/website/docs/reference/scala-command/runner-specification.md b/website/docs/reference/scala-command/runner-specification.md index 0cae4c533d..33d93e0ee3 100644 --- a/website/docs/reference/scala-command/runner-specification.md +++ b/website/docs/reference/scala-command/runner-specification.md @@ -3936,7 +3936,7 @@ Aliases: `--dialect` **--scalafmt-version** -Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. +Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file. Aliases: `--fmt-version`