From c5080cf9808c3ba7eaf86bd1ad3a842994186430 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:32:36 -0800 Subject: [PATCH 1/3] Scalafmt: expand Error.WithCode in external format --- .../shared/src/main/scala/org/scalafmt/Scalafmt.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/Scalafmt.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/Scalafmt.scala index ab17cea27..fafc0f572 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/Scalafmt.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/Scalafmt.scala @@ -57,7 +57,10 @@ object Scalafmt { style: ScalafmtConfig, range: Set[Range], filename: String, - ): Formatted = formatCode(code, style, range, filename).formatted + ): Formatted = formatCode(code, style, range, filename).formatted match { + case Formatted.Failure(Error.WithCode(ex, _)) => Formatted.Failure(ex) + case x => x + } private[scalafmt] def formatCode( code: String, @@ -137,7 +140,7 @@ object Scalafmt { code: String, style: ScalafmtConfig = ScalafmtConfig.default, range: Set[Range] = Set.empty[Range], - ): Formatted = formatCode(code, style, range).formatted + ): Formatted = format(code, style, range, defaultFilename) // used by ScalafmtReflect.parseConfig def parseHoconConfigFile(configPath: Path): Configured[ScalafmtConfig] = From 165cd345d0e5c8d11878a37170ddcfc53927af42 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:33:33 -0800 Subject: [PATCH 2/3] Error: use nested error message in WithCode --- scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala index c7ad8c310..11dc6282b 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala @@ -120,6 +120,7 @@ object Error { case object MegaTestFailed extends Error("Mega test failed.") - case class WithCode(error: Throwable, code: String) extends Exception(error) + case class WithCode(error: Throwable, code: String) + extends Exception(error.getMessage, error) } From f68d07f8272b844398ba9277313124c04a53a58f Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:33:54 -0800 Subject: [PATCH 3/3] DynamicSuite: use non-RC version for `latest` --- .../org/scalafmt/dynamic/DynamicSuite.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 7c40f17fe..aaf750756 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 @@ -210,6 +210,7 @@ class DynamicSuite extends FunSuite { ) } } + checkParseError(nightly, "scala212") checkParseError(latest, "scala212") checkParseError("1.0.0", "Scala211") @@ -386,8 +387,10 @@ class DynamicSuite extends FunSuite { } } } + checkSbt(nightly, "scala213") checkSbt(latest, "scala213") checkSbt("3.8.0", "scala213") + checkSbt(nightly, "scala211") checkSbt(latest, "scala211") checkSbt("3.8.0", "scala211") checkSbt("1.2.0", "Scala211") @@ -607,7 +610,18 @@ class DynamicSuite extends FunSuite { private object DynamicSuite { def nightly = BuildInfo.nightly - def latest = BuildInfo.previousStable + def latest = { + val latest = BuildInfo.previousStable + ScalafmtVersion.parse(latest).flatMap { ver => + if (ver.rc <= 0 && ver.snapshot.isEmpty) None + else if (ver.patch > 0) + Some(ScalafmtVersion(ver.major, ver.minor, ver.patch - 1).toString) + else if (ver.minor > 0) + Some(ScalafmtVersion(ver.major, ver.minor - 1, 0).toString) + else if (ver.major > 0) Some(ScalafmtVersion(ver.major - 1, 0, 0).toString) + else None + }.getOrElse(latest) + } def getDialectError(version: String, dialect: String, sbt: Boolean = false) = if (version < "3.1.0") "" else s" [dialect ${if (sbt) "sbt" else dialect}]"