diff --git a/.scalafmt.conf b/.scalafmt.conf index 85fbd5e01d..06cc8da00e 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version=2.0.0-RC5 +version=2.3.0-RC2 project.git = true project.excludeFilters = [ scalafmt-benchmarks/src/resources, diff --git a/project/plugins.sbt b/project/plugins.sbt index f28ad9ccb7..911de31d8c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,7 +5,7 @@ resolvers ++= Seq( ) addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.3.6") -addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC4") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.2.1") addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.4.31") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") addSbtPlugin( diff --git a/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala b/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala index cc9f8ba93a..301577150b 100644 --- a/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala +++ b/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala @@ -131,12 +131,11 @@ object CliArgParser { "test for mis-formatted code, exits with status 1 on first failure." ) opt[File]("migrate2hocon") - .action( - (file, c) => - c.copy( - migrate = - Some(AbsoluteFile.fromFile(file, c.common.workingDirectory)) - ) + .action((file, c) => + c.copy( + migrate = + Some(AbsoluteFile.fromFile(file, c.common.workingDirectory)) + ) ) .text( """migrate .scalafmt CLI style configuration to hocon style configuration in .scalafmt.conf""" diff --git a/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala b/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala index d1d3975d91..af2ace20dc 100644 --- a/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala +++ b/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala @@ -169,7 +169,8 @@ object TermDisplay { s"Last update: ${formatTimestamp(remote)}" case (None, None) => "" // ??? - } else + } + else currentTimeOpt match { case Some(current) => s"Checking for updates since ${formatTimestamp(current)}" diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Edition.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Edition.scala index 0e5329db7a..b35f8c20e4 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Edition.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Edition.scala @@ -18,7 +18,7 @@ object Edition { } implicit val encoder: ConfEncoder[Edition] = - ConfEncoder.instance( - edition => Conf.Str(f"${edition.year}%d-${edition.month}%02d") + ConfEncoder.instance(edition => + Conf.Str(f"${edition.year}%d-${edition.month}%02d") ) } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 41cbdeca28..68ecd4d84c 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -888,12 +888,11 @@ class Router(formatOps: FormatOps) { }, comma.right.end) case _ => NoPolicy } - val optToken = nextComma.map( - _ => - OptimalToken( - rhsOptimalToken(leftTok2tok(nextArg.tokens.last)), - killOnFail = true - ) + val optToken = nextComma.map(_ => + OptimalToken( + rhsOptimalToken(leftTok2tok(nextArg.tokens.last)), + killOnFail = true + ) ) Seq( Split(Space, 0, optimalAt = optToken).withPolicy(singleLine), @@ -1581,10 +1580,9 @@ class Router(formatOps: FormatOps) { else newlineSplits case FormatToken(_, c: T.Comment, between) if newlinesBetween(between) == 0 && c.syntax.startsWith("//") => - splits.map( - x => - if (x.modification.isNewline) x.copy(modification = Space) - else x + splits.map(x => + if (x.modification.isNewline) x.copy(modification = Space) + else x ) case _ => splits } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala index dd521cbd89..2a08a8beb6 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala @@ -43,11 +43,10 @@ case object AvoidInfix extends Rewrite { val selectorParens = for { fstToken <- fstArgsToken lastToken <- lastArgsToken - } yield - Seq( - TokenPatch.AddLeft(fstToken, "(", keepTok = true), - TokenPatch.AddRight(lastToken, ")", keepTok = true) - ) + } yield Seq( + TokenPatch.AddLeft(fstToken, "(", keepTok = true), + TokenPatch.AddRight(lastToken, ")", keepTok = true) + ) selectorParens.getOrElse(Seq.empty) } else Nil @@ -67,18 +66,16 @@ case object AvoidInfix extends Rewrite { case _ => Nil } - val toBeRemoved = fstArgsToken.fold(Seq.empty[TokenPatch])( - token => - ctx.tokenTraverser - .filter(fstOpToken, token)(_.is[LF]) - .map(TokenPatch.Remove) + val toBeRemoved = fstArgsToken.fold(Seq.empty[TokenPatch])(token => + ctx.tokenTraverser + .filter(fstOpToken, token)(_.is[LF]) + .map(TokenPatch.Remove) ) - val hasSingleLineComment = fstArgsToken.exists( - token => - ctx.tokenTraverser - .filter(fstOpToken, token)(TokenOps.isSingleLineComment) - .nonEmpty + val hasSingleLineComment = fstArgsToken.exists(token => + ctx.tokenTraverser + .filter(fstOpToken, token)(TokenOps.isSingleLineComment) + .nonEmpty ) val infixTokens = infix.tokens diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ExpandImportSelectors.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ExpandImportSelectors.scala index 5673cb44e0..062559b9c3 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ExpandImportSelectors.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/ExpandImportSelectors.scala @@ -13,10 +13,9 @@ case object ExpandImportSelectors extends Rewrite { .map { `import` => val expandedImport = `import`.collect { case importer @ Importer(path, importees) => - val hasRenamesOrUnimports = importees.exists( - importee => - importee.is[Importee.Rename] || importee - .is[Importee.Unimport] + val hasRenamesOrUnimports = importees.exists(importee => + importee.is[Importee.Rename] || importee + .is[Importee.Unimport] ) val hasWildcards = importees.exists(_.is[Importee.Wildcard]) @@ -45,9 +44,8 @@ case object ExpandImportSelectors extends Rewrite { .groupBy(_.tok) val mergedPatches: Seq[Patch] = groupedPatches.values.map { patches => - patches.reduce( - (p1: TokenPatch, p2: TokenPatch) => - TokenPatch.AddRight(p1.tok, p1.newTok + "\n" + p2.newTok) + patches.reduce((p1: TokenPatch, p2: TokenPatch) => + TokenPatch.AddRight(p1.tok, p1.newTok + "\n" + p2.newTok) ) }.toSeq diff --git a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflect.scala b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflect.scala index d2a966820e..07b1446710 100644 --- a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflect.scala +++ b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflect.scala @@ -67,19 +67,20 @@ case class ScalafmtReflect( } def parseConfigFromString(configText: String): ScalafmtReflectConfig = { - val configured: Object = try { // scalafmt >= 1.6.0 - scalafmtCls.invokeStatic("parseHoconConfig", configText.asParam) - } catch { - case _: NoSuchMethodException => - // scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0 - val fromHoconEmptyPath = - configCls.invokeStatic("fromHoconString$default$2") - configCls.invokeStatic( - "fromHoconString", - configText.asParam, - fromHoconEmptyPath.asParam(optionCls) - ) - } + val configured: Object = + try { // scalafmt >= 1.6.0 + scalafmtCls.invokeStatic("parseHoconConfig", configText.asParam) + } catch { + case _: NoSuchMethodException => + // scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0 + val fromHoconEmptyPath = + configCls.invokeStatic("fromHoconString$default$2") + configCls.invokeStatic( + "fromHoconString", + configText.asParam, + fromHoconEmptyPath.asParam(optionCls) + ) + } try { new ScalafmtReflectConfig(this, configured.invoke("get"), classLoader) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/FidelityTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/FidelityTest.scala index 4808c4571f..a6c0f10efb 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/FidelityTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/FidelityTest.scala @@ -27,16 +27,15 @@ class FidelityTest extends FunSuite with FormatAssertions { val files = FileOps .listFiles(".") .filter(_.endsWith(".scala")) - .filterNot( - x => - Set( - "ConfigReader.scala", - "BuildTime.scala", - "GitCommit.scala", - "/target/", - "/resources/", - "/gh-pages/" - ).map(_.replace("/", File.separator)).exists(x.contains) + .filterNot(x => + Set( + "ConfigReader.scala", + "BuildTime.scala", + "GitCommit.scala", + "/target/", + "/resources/", + "/gh-pages/" + ).map(_.replace("/", File.separator)).exists(x.contains) ) val examples = files.map(Test.apply) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/Tabulator.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/Tabulator.scala index 28a33c2670..113c47aa8e 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/Tabulator.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/Tabulator.scala @@ -11,9 +11,9 @@ object Tabulator { def format(table: Seq[Seq[Any]]) = table match { case Seq() => "" case _ => - val sizes = for (row <- table) - yield - (for (cell <- row) + val sizes = + for (row <- table) + yield (for (cell <- row) yield if (cell == null) 0 else cell.toString.length) @@ -27,10 +27,11 @@ object Tabulator { )).mkString("\n") def formatRow(row: Seq[Any], colSizes: Seq[Int]) = { - val cells = (for ((item, size) <- row.zip(colSizes)) - yield - if (size == 0) "" - else ("%" + size + "s").format(item)) + val cells = + (for ((item, size) <- row.zip(colSizes)) + yield + if (size == 0) "" + else ("%" + size + "s").format(item)) cells.mkString("|", "|", "|") }