From d76cb7c0df1160049aa59fbbfaab7f9543db5da6 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 30 Mar 2024 08:06:38 -0700 Subject: [PATCH] scalafmt: align strip margins --- .scalafmt.conf | 1 + .../scala/org/scalafmt/readme/Readme.scala | 12 +- .../src/main/scala/org/scalafmt/cli/Cli.scala | 42 +- .../scala/org/scalafmt/cli/CliArgParser.scala | 61 +- .../src/main/scala/org/scalafmt/Error.scala | 20 +- .../org/scalafmt/config/NamedDialect.scala | 6 +- .../org/scalafmt/config/ProjectFiles.scala | 2 +- .../scalafmt/internal/BestFirstSearch.scala | 18 +- .../org/scalafmt/internal/FormatOps.scala | 10 +- .../scala/org/scalafmt/rewrite/Patch.scala | 6 +- .../scala/org/scalafmt/util/LoggerOps.scala | 17 +- .../org/scalafmt/dynamic/DynamicSuite.scala | 160 +-- .../test/scala/org/scalafmt/CommentTest.scala | 192 ++-- .../org/scalafmt/CustomStructureTest.scala | 6 +- .../test/scala/org/scalafmt/RangeTest.scala | 20 +- .../scala/org/scalafmt/ScalafmtProps.scala | 4 +- .../org/scalafmt/ScalafmtRunnerTest.scala | 18 +- .../scala/org/scalafmt/ScalafmtTest.scala | 50 +- .../test/scala/org/scalafmt/UnitTests.scala | 6 +- .../org/scalafmt/cli/CliOptionsTest.scala | 14 +- .../test/scala/org/scalafmt/cli/CliTest.scala | 952 +++++++++--------- .../scala/org/scalafmt/cli/FileTestOps.scala | 2 +- .../scalafmt/config/ScalafmtConfigTest.scala | 56 +- .../scala/org/scalafmt/util/HasTests.scala | 6 +- .../test/scala/org/scalafmt/util/Report.scala | 10 +- .../org/scalafmt/util/StyleMapTest.scala | 48 +- 26 files changed, 872 insertions(+), 867 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index ed7c0ff472..966d749070 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -10,6 +10,7 @@ project { } align { preset = none + stripMargin = true } newlines { avoidForSimpleOverflow = [punct, slc, tooLong] diff --git a/readme/src/main/scala/org/scalafmt/readme/Readme.scala b/readme/src/main/scala/org/scalafmt/readme/Readme.scala index 6d111bb545..5b518887c1 100644 --- a/readme/src/main/scala/org/scalafmt/readme/Readme.scala +++ b/readme/src/main/scala/org/scalafmt/readme/Readme.scala @@ -54,14 +54,14 @@ object Readme { val expressions = s"{$code}".parse[Stat].get.asInstanceOf[Term.Block].stats val evaluated = eval[Any](code) val output = evaluated match { - case s: String => s""" - |"$s"""".stripMargin + case s: String => s"""| + |"$s"""".stripMargin case x => x.toString } - val result = - s"""${expressions.map(x => s"scala> ${x.toString().trim}").mkString("\n")} - |res0: ${evaluated.getClass.getName} = $output - |""".stripMargin + val result = s"""|${expressions.map(x => s"scala> ${x.toString().trim}") + .mkString("\n")} + |res0: ${evaluated.getClass.getName} = $output + |""".stripMargin hl.scala(result) } diff --git a/scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala b/scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala index 981d96507d..699419c33d 100644 --- a/scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala +++ b/scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala @@ -101,11 +101,11 @@ object Cli { private def findRunner(options: CliOptions): MaybeRunner = options.hoconOpt .fold[MaybeRunner] { Left( - s"""error: missing Scalafmt configuration file. - |Consider creating '${options.getProposedConfigFile}' - |with the following (other parameters may also be required): - |${getProposedConfigVersion(options)} - |""".stripMargin + s"""|error: missing Scalafmt configuration file. + |Consider creating '${options.getProposedConfigFile}' + |with the following (other parameters may also be required): + |${getProposedConfigVersion(options)} + |""".stripMargin ) } { // Run format using @@ -119,10 +119,10 @@ object Cli { case _ => "--config-str option" } Left( - s"""error: missing Scalafmt version. - |Consider adding the following to $where: - |${getProposedConfigVersion(options)} - |""".stripMargin + s"""|error: missing Scalafmt version. + |Consider adding the following to $where: + |${getProposedConfigVersion(options)} + |""".stripMargin ) } { case Left(error) => Left(s"error: invalid configuration: ${error}") @@ -131,18 +131,18 @@ object Cli { Right(ScalafmtCoreRunner) case Right(v) if isNativeImage => Left( - s"""error: invalid Scalafmt version. - | - |This Scalafmt installation has version '$stableVersion' and the version configured in '${options - .configPath}' is '$v'. - |To fix this problem, add the following line to .scalafmt.conf: - |``` - |version = $stableVersion - |``` - | - |NOTE: this error happens only when running a native Scalafmt binary. - |Scalafmt automatically installs and invokes the correct version of Scalafmt when running on the JVM. - |""".stripMargin + s"""|error: invalid Scalafmt version. + | + |This Scalafmt installation has version '$stableVersion' and the version configured in '${options + .configPath}' is '$v'. + |To fix this problem, add the following line to .scalafmt.conf: + |``` + |version = $stableVersion + |``` + | + |NOTE: this error happens only when running a native Scalafmt binary. + |Scalafmt automatically installs and invokes the correct version of Scalafmt when running on the JVM. + |""".stripMargin ) case Right(v) => options.common.debug.println(s"Using dynamic runner [$v]") 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 ad07a9332a..369d2950ea 100644 --- a/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala +++ b/scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala @@ -12,20 +12,20 @@ object CliArgParser { val usageExamples: String = """|scalafmt # Format all files in the current project, configuration is determined in this order: - | # 1. .scalafmt.conf file in current directory - | # 2. .scalafmt.conf inside root directory of current git repo - | # 3. no configuration, default style - |scalafmt --test # throw exception on mis-formatted files, won't write to files. - |scalafmt --mode diff # Format all files that were edited in git diff against master branch. - |scalafmt --mode changed # Format files listed in `git status` (latest changes against previous commit. - |scalafmt --diff-branch 2.x # same as --diff, except against branch 2.x - |scalafmt --stdin # read from stdin (doesn't imply --stdout) - |scalafmt --stdin --assume-filename foo.sbt < foo.sbt # required when using --stdin to format .sbt files. - |scalafmt Code1.scala A.scala # write formatted contents to file. - |scalafmt --stdout Code.scala # print formatted contents to stdout. - |scalafmt --exclude target # format all files in directory excluding target - |scalafmt --config .scalafmt.conf # read custom style from file. - |scalafmt --config-str "style=IntelliJ" # define custom style as a flag, must be quoted.""" + | # 1. .scalafmt.conf file in current directory + | # 2. .scalafmt.conf inside root directory of current git repo + | # 3. no configuration, default style + |scalafmt --test # throw exception on mis-formatted files, won't write to files. + |scalafmt --mode diff # Format all files that were edited in git diff against master branch. + |scalafmt --mode changed # Format files listed in `git status` (latest changes against previous commit. + |scalafmt --diff-branch 2.x # same as --diff, except against branch 2.x + |scalafmt --stdin # read from stdin (doesn't imply --stdout) + |scalafmt --stdin --assume-filename foo.sbt < foo.sbt # required when using --stdin to format .sbt files. + |scalafmt Code1.scala A.scala # write formatted contents to file. + |scalafmt --stdout Code.scala # print formatted contents to stdout. + |scalafmt --exclude target # format all files in directory excluding target + |scalafmt --config .scalafmt.conf # read custom style from file. + |scalafmt --config-str "style=IntelliJ" # define custom style as a flag, must be quoted.""" .stripMargin val scoptParser: OptionParser[CliOptions] = @@ -53,9 +53,9 @@ object CliArgParser { arg[Path]("...").optional().unbounded().action((file, c) => c.addFile(file) ).text( - """file, or directory (in which all *.scala files are to be formatted); - |if starts with '@', refers to path listing files to be formatted - |(with "@-" referring to standard input as a special case)""" + """|file, or directory (in which all *.scala files are to be formatted); + |if starts with '@', refers to path listing files to be formatted + |(with "@-" referring to standard input as a special case)""" .stripMargin ) @@ -99,20 +99,20 @@ object CliArgParser { writeMode(c, WriteMode.Test).copy(error = true, check = true) ).text("test for mis-formatted code only, exits with status 1 on first failure.") opt[FileFetchMode]("mode").action((m, c) => c.copy(mode = Option(m))).text( - s"""Sets the files to be formatted fetching mode. - |Options: - |${FileFetchMode.help} - |""".stripMargin + s"""|Sets the files to be formatted fetching mode. + |Options: + |${FileFetchMode.help} + |""".stripMargin ) opt[Unit]("diff") .action((_, c) => c.copy(mode = Option(DiffFiles("master")))).text( - s"""Format files listed in `git diff` against master. - |Deprecated: use --mode diff instead""".stripMargin + s"""|Format files listed in `git diff` against master. + |Deprecated: use --mode diff instead""".stripMargin ) opt[String]("diff-branch") .action((branch, c) => c.copy(mode = Option(DiffFiles(branch)))).text( - s"""Format files listed in `git diff` against given git ref. - |Deprecated: use --mode diff-ref= instead""".stripMargin + s"""|Format files listed in `git diff` against given git ref. + |Deprecated: use --mode diff-ref= instead""".stripMargin ) opt[Unit]("build-info").action((_, _) => { println(buildInfo); sys.exit }) .text("prints build information") @@ -132,9 +132,9 @@ object CliArgParser { note( s"""|Examples: - |$usageExamples - |Please file bugs to https://github.com/scalameta/scalafmt/issues - """.stripMargin + |$usageExamples + |Please file bugs to https://github.com/scalameta/scalafmt/issues + |""".stripMargin ) checkConfig { c => @@ -143,8 +143,9 @@ object CliArgParser { else success } } - def buildInfo = s"""build commit: ${Versions.commit} - |build time: ${new Date(Versions.timestamp.toLong)}""".stripMargin + def buildInfo = + s"""|build commit: ${Versions.commit} + |build time: ${new Date(Versions.timestamp.toLong)}""".stripMargin private def writeMode(c: CliOptions, writeMode: WriteMode): CliOptions = c .writeModeOpt.fold { c.copy(writeModeOpt = Some(writeMode)) } { x => 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 7ae2750c99..210b99e954 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala @@ -41,14 +41,14 @@ object Error { case class FormatterChangedAST(diff: String, output: String) extends Error( - s"""Formatter changed AST - |===================== - |$diff - |===================== - |${output.linesIterator.toVector.take(10).mkString("\n")} - |===================== - |Formatter changed AST - """.stripMargin + s"""|Formatter changed AST + |===================== + |$diff + |===================== + |${output.linesIterator.toVector.take(10).mkString("\n")} + |===================== + |Formatter changed AST + |""".stripMargin ) case class FormatterOutputDoesNotParse(msg: String, line: Int) @@ -56,8 +56,8 @@ object Error { case class UnexpectedTree[Expected <: Tree: ClassTag](obtained: Tree) extends Error( - s"""Expected: ${classTag[Expected].runtimeClass.getName} - |Obtained: ${log(obtained)}""".stripMargin + s"""|Expected: ${classTag[Expected].runtimeClass.getName} + |Obtained: ${log(obtained)}""".stripMargin ) case class CantFormatFile(msg: String) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala index c2026367cc..c13cab1f60 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala @@ -39,9 +39,9 @@ object NamedDialect { def getUnknownError = { val knownStr = known.map(_.name).mkString(",") - s"""Default dialect is deprecated; use explicit: [$knownStr] - |Also see https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects" - |""".stripMargin + s"""|Default dialect is deprecated; use explicit: [$knownStr] + |Also see https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects" + |""".stripMargin } implicit val codec: ConfCodecEx[NamedDialect] = ReaderUtil diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala index da9230f31e..9741c37a79 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala @@ -85,7 +85,7 @@ object ProjectFiles { case e: java.util.regex.PatternSyntaxException => throw new ScalafmtConfigException( s"""|Illegal regex in configuration: $regex - |reason: ${e.getMessage()}""".stripMargin + |reason: ${e.getMessage()}""".stripMargin ) } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala index de6648b180..dae43968f1 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala @@ -290,17 +290,17 @@ private class BestFirstSearch private ( val tok = tokens(deepestYet.depth) val splitsAfterPolicy = deepestYet.policy .execute(Decision(tok, nextSplits)) - val msg = s"""UNABLE TO FORMAT, - |tok=$tok - |toks.length=${tokens.length} - |deepestYet.length=${deepestYet.depth} - |policies=${deepestYet.policy.policies} - |nextSplits=$nextSplits - |splitsAfterPolicy=$splitsAfterPolicy""".stripMargin + val msg = s"""|UNABLE TO FORMAT, + |tok=$tok + |toks.length=${tokens.length} + |deepestYet.length=${deepestYet.depth} + |policies=${deepestYet.policy.policies} + |nextSplits=$nextSplits + |splitsAfterPolicy=$splitsAfterPolicy""".stripMargin if (runner.debug) { logger.debug( - s"""Failed to format - |$msg""".stripMargin + s"""|Failed to format + |$msg""".stripMargin ) } complete(deepestYet) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 81a1b3a539..c5250fa2b3 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1341,11 +1341,11 @@ class FormatOps( case _ if orNil => Nil case t => logger.debug( - s"""getApplyArgs: unknown tree - |Tree: ${log(t)} - |Parent: ${log(t.parent)} - |GrandParent: ${log(t.parent.flatMap(_.parent))} - |""".stripMargin + s"""|getApplyArgs: unknown tree + |Tree: ${log(t)} + |Parent: ${log(t.parent)} + |GrandParent: ${log(t.parent.flatMap(_.parent))} + |""".stripMargin ) throw UnexpectedTree[Member.SyntaxValuesClause](t) } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/Patch.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/Patch.scala index b50cd4e717..a5e21f8612 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/Patch.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/Patch.scala @@ -40,9 +40,9 @@ object Patch { case (add: Add, _: Remove) => add.copy(keepTok = false) case (rem: Remove, _: Remove) => rem case _ => sys.error( - s"""Can't merge token patches: - |1. $a - |2. $b""".stripMargin + s"""|Can't merge token patches: + |1. $a + |2. $b""".stripMargin ) } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/LoggerOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/LoggerOps.scala index 07f7e6d558..109a65c003 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/LoggerOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/LoggerOps.scala @@ -28,9 +28,10 @@ object LoggerOps { } def log(split: Split): String = s"$split" - def log(formatToken: FormatToken): String = s"""${log(formatToken.left)} - |${log(formatToken.between: _*)} - |${log(formatToken.right)}""".stripMargin + def log(formatToken: FormatToken): String = + s"""|${log(formatToken.left)} + |${log(formatToken.between: _*)} + |${log(formatToken.right)}""".stripMargin def log2(formatToken: FormatToken): String = formatToken.toString @@ -52,11 +53,11 @@ object LoggerOps { def log(t: Tree, tokensOnly: Boolean): String = { val tokens = s"TOKENS: ${t.tokens.map(x => reveal(x.syntax)).mkString(",")}" if (tokensOnly) tokens - else s"""TYPE: ${t.getClass.getName.stripPrefix("scala.meta.")} - |SOURCE: $t - |STRUCTURE: ${t.show[Structure]} - |$tokens - |""".stripMargin + else s"""|TYPE: ${t.getClass.getName.stripPrefix("scala.meta.")} + |SOURCE: $t + |STRUCTURE: ${t.show[Structure]} + |$tokens + |""".stripMargin } def log(t: Option[Tree]): String = log(t, false) diff --git a/scalafmt-dynamic/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala b/scalafmt-dynamic/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala index 284dd0459f..210fe587eb 100644 --- a/scalafmt-dynamic/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala +++ b/scalafmt-dynamic/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala @@ -77,11 +77,11 @@ class DynamicSuite extends FunSuite { def setVersion(newVersion: String, dialect: String, rest: String*): Unit = { val dialectLine = Option(dialect).fold("")(x => s"runner.dialect = $x") setConfig( - s""" - |version="$newVersion" - |$dialectLine - |${rest.mkString("\n")} - |""".stripMargin + s"""| + |version="$newVersion" + |$dialectLine + |${rest.mkString("\n")} + |""".stripMargin ) } def relevant: String = { @@ -213,8 +213,8 @@ class DynamicSuite extends FunSuite { f.assertError( code, s"""|$name.scala:1:8: error:$dialectError ${bq}identifier$bq expected but ${bq}object$bq found - |$code - | ^^^^^^""".stripMargin + |$code + | ^^^^^^""".stripMargin ) } } @@ -224,14 +224,14 @@ 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") @@ -243,14 +243,14 @@ 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") @@ -266,40 +266,40 @@ class DynamicSuite extends FunSuite { assertNoDiff( err.takeRight(120), """|error: found option 'max' which wasn't expected, or isn't valid in this context. - | Did you mean 'maxColumn'? - |max = 70 - |^ - |""".stripMargin + | Did you mean 'maxColumn'? + |max = 70 + |^ + |""".stripMargin ) } check("regex-error") { f => f.setConfig( s"""|version = "$nightly" - |runner.dialect = "scala212" - |project.excludeFilters = [ - | ".*foo(" - |] - |""".stripMargin + |runner.dialect = "scala212" + |project.excludeFilters = [ + | ".*foo(" + |] + |""".stripMargin ) val err = f.assertThrows[ScalafmtDynamicError.ConfigParseError]().getMessage assertNoDiff( err.takeRight(120), """|Invalid config: Illegal regex in configuration: .*foo( - |reason: Unclosed group near index 6 - |.*foo( - |""".stripMargin + |reason: Unclosed group near index 6 + |.*foo( + |""".stripMargin ) } check("path-error") { f => f.setConfig( s"""|version = "$nightly" - |runner.dialect = "scala212" - |project.excludePaths = [ - | "foo.scala" - |] - |""".stripMargin + |runner.dialect = "scala212" + |project.excludePaths = [ + | "foo.scala" + |] + |""".stripMargin ) val err = f.assertThrows[ScalafmtDynamicError.ConfigParseError]().getMessage assertNoDiff( @@ -367,8 +367,8 @@ class DynamicSuite extends FunSuite { else f.assertError( "lazy val x = project", s"""|$name.scala:1:1: error:$dialectError classes cannot be lazy - |lazy val x = project - |^^^^""".stripMargin + |lazy val x = project + |^^^^""".stripMargin ) // check wrapped literals, supported in sbt using scala 2.13+ val wrappedLiteral = "object a { val x: Option[0] = Some(0) }" @@ -377,8 +377,8 @@ class DynamicSuite extends FunSuite { f.assertError( wrappedLiteral, s"""$filename:1:28: error:$dialectError ${bq}identifier$bq expected but ${bq}integer constant$bq found - |$wrappedLiteral - | ^""".stripMargin, + |$wrappedLiteral + | ^""".stripMargin, path ) } @@ -425,28 +425,28 @@ 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) } @@ -496,41 +496,41 @@ class DynamicSuite extends FunSuite { check("invalid config in 3.0.0-RC6") { f => f.setConfig( s"""|version=3.0.0-RC6 - |align=does-not-exist - |""".stripMargin + |align=does-not-exist + |""".stripMargin ) val thrown = f.assertThrows[ScalafmtDynamicError.ConfigParseError]() assertNoDiff( thrown.getMessage, """|Invalid config: :3:0 error: Type mismatch; - | found : String (value: "does-not-exist") - | expected : Object - | "align" : "does-not-exist", - |^ - |""".stripMargin + | found : String (value: "does-not-exist") + | expected : Object + | "align" : "does-not-exist", + |^ + |""".stripMargin ) } check("invalid config in 2.7.5") { f => f.setConfig( s"""|version=2.7.5 - |align=does-not-exist - |""".stripMargin + |align=does-not-exist + |""".stripMargin ) val thrown = f.assertThrows[ScalafmtDynamicError.ConfigParseError]() assertNoDiff( thrown.getMessage, """|Invalid config: Type mismatch; - | found : String (value: "does-not-exist") - | expected : Object - |""".stripMargin + | found : String (value: "does-not-exist") + | expected : Object + |""".stripMargin ) } check("invalid version - current") { f => f.setConfig( s"""|version=current - |""".stripMargin + |""".stripMargin ) val error = f.assertThrows[ScalafmtDynamicError.ConfigInvalidVersion]() .getMessage @@ -540,7 +540,7 @@ class DynamicSuite extends FunSuite { check("invalid version - missing") { f => f.setConfig( s"""|maxColumn = 40 - |""".stripMargin + |""".stripMargin ) val error = f.assertThrows[ScalafmtDynamicError.ConfigMissingVersion]() .getMessage diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/CommentTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/CommentTest.scala index 155103b295..1a6a543fee 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/CommentTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/CommentTest.scala @@ -13,114 +13,114 @@ class CommentTest extends FunSuite { test("remove trailing space in comments") { val trailingSpace = " " - val original = s"""object a { - | // inline comment$trailingSpace - |/**$trailingSpace - | * Y is cool$trailingSpace - | */ - |/*$trailingSpace - | * X is cool$trailingSpace - | */ - |/* - | 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 original = s"""|object a { + | // inline comment$trailingSpace + |/**$trailingSpace + | * Y is cool$trailingSpace + | */ + |/*$trailingSpace + | * X is cool$trailingSpace + | */ + |/* + | 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) } test("remove trailing tabs in comments") { val trailingSpace = "\t \t" - val original = s"""object a { - | // inline comment$trailingSpace - |/**$trailingSpace - | * Y is cool$trailingSpace - | */ - |/*$trailingSpace - | * X is cool$trailingSpace - | */ - |/* - | 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 original = s"""|object a { + | // inline comment$trailingSpace + |/**$trailingSpace + | * Y is cool$trailingSpace + | */ + |/*$trailingSpace + | * X is cool$trailingSpace + | */ + |/* + | 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) } test("remove various trailing Unicode whitespace in comments") { val trailingSpace = "    " // U+00A0, U+2000, U+1680, U+3000 - val original = s"""object a { - | // inline comment$trailingSpace - |/**$trailingSpace - | * Y is cool$trailingSpace - | */ - |/*$trailingSpace - | * X is cool$trailingSpace - | */ - |/* - | 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 original = s"""|object a { + | // inline comment$trailingSpace + |/**$trailingSpace + | * Y is cool$trailingSpace + | */ + |/*$trailingSpace + | * X is cool$trailingSpace + | */ + |/* + | 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/src/test/scala/org/scalafmt/CustomStructureTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/CustomStructureTest.scala index ca73725717..b152153e4d 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/CustomStructureTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/CustomStructureTest.scala @@ -16,9 +16,9 @@ class CustomStructureTest extends FunSuite { // #3634 check( - """ - |def foo(a: Foo[_]): Unit = ??? - """.stripMargin, + """| + |def foo(a: Foo[_]): Unit = ??? + | """.stripMargin, Defn.Def( Nil, Term.Name("foo"), diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/RangeTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/RangeTest.scala index 7f69f3b499..c8d5b69bfd 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/RangeTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/RangeTest.scala @@ -5,16 +5,16 @@ import org.scalafmt.util.HasTests 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/src/test/scala/org/scalafmt/ScalafmtProps.scala b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtProps.scala index f56fb4e3b0..887217544c 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtProps.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtProps.scala @@ -73,8 +73,8 @@ class ScalafmtProps extends FunSuite with FormatAssertions { val summary = bugs.groupBy(_._2.kind.toString).mapValues(_.length).toSeq .sortBy(_._2).map { case (a, b) => s"$a=$b" }.mkString("\n") val report = s"""|$summary - | - |$table """.stripMargin + | + |$table """.stripMargin logger.elem(summary) logger.elem(report) logger.elem(summary) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtRunnerTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtRunnerTest.scala index 7d62ed5b3c..2efc7c24d2 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtRunnerTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtRunnerTest.scala @@ -7,15 +7,15 @@ import munit.FunSuite class ScalafmtRunnerTest extends FunSuite { test("sbt dialect supports trailing commas") { ScalafmtRunner.sbt.getDialect( - """ - |lazy - |val x = project( - | a, - | - | - | b, - |) - """.stripMargin + """| + |lazy + |val x = project( + | a, + | + | + | b, + |) + | """.stripMargin ).parse[Source].get } } diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtTest.scala index 56f300e856..ba5806ccae 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/ScalafmtTest.scala @@ -17,41 +17,41 @@ class ScalafmtTest extends FunSuite { } } check( - """ - |object A { println ("HELLO!" ) } - | - | - |// comment - """.stripMargin, + """| + |object A { println ("HELLO!" ) } + | + | + |// comment + | """.stripMargin, """|object A { println("HELLO!") } - | - |// comment - |""".stripMargin + | + |// comment + |""".stripMargin ) check( """|object A { - | val x = 2 - | val xx = 3 - |} - """.stripMargin, + | val x = 2 + | val xx = 3 + |} + | """.stripMargin, """|object A { - | val x = 2 - | val xx = 3 - |} - |""".stripMargin, + | val x = 2 + | val xx = 3 + |} + |""".stripMargin, config.ScalafmtConfig.defaultWithAlign ) check( """|object A { function(aaaaaaaa, bbbbbbbbbb, ddddd(eeeeeeeeee, fffffff, gggggggg)) } - """.stripMargin, + | """.stripMargin, """|object A { - | function( - | aaaaaaaa, - | bbbbbbbbbb, - | ddddd(eeeeeeeeee, fffffff, gggggggg) - | ) - |} - |""".stripMargin, + | function( + | aaaaaaaa, + | bbbbbbbbbb, + | ddddd(eeeeeeeeee, fffffff, gggggggg) + | ) + |} + |""".stripMargin, config.ScalafmtConfig.default.copy(maxColumn = 40) ) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/UnitTests.scala b/scalafmt-tests/src/test/scala/org/scalafmt/UnitTests.scala index dc2af6e720..d27d13bc5c 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/UnitTests.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/UnitTests.scala @@ -24,9 +24,9 @@ object UnitTests extends HasTests { } yield { if (sys.env.contains("CI") && test.only) { sys.error( - s"""Please remove ONLY from test '${test.name}' in file '$filename'. - |Tests with ONLY will not be merged, this feature is only meant to be used for local development. - """.stripMargin + s"""|Please remove ONLY from test '${test.name}' in file '$filename'. + |Tests with ONLY will not be merged, this feature is only meant to be used for local development. + | """.stripMargin ) } test diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala index 82023eaf5d..3a2ce3d222 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala @@ -23,8 +23,8 @@ class CliOptionsTest extends FunSuite { assertEquals( ScalafmtConfig.fromHoconString( """|preset = defaultWithAlign - |maxColumn = 100 - |""".stripMargin + |maxColumn = 100 + |""".stripMargin ), Configured.ok(ScalafmtConfig.defaultWithAlign.copy(maxColumn = 100)) ) @@ -73,11 +73,11 @@ class CliOptionsTest extends FunSuite { test(".scalafmtConfig returns the configuration read from configuration file located on configPath") { val expected = "foo bar" val configPath = Files.createTempFile(".scalafmt", ".conf") - val config = s""" - |version="${Versions.version}" - |maxColumn=100 - |onTestFailure="$expected" - |""".stripMargin + val config = s"""| + |version="${Versions.version}" + |maxColumn=100 + |onTestFailure="$expected" + |""".stripMargin Files.write(configPath, config.getBytes) val opt = baseCliOptions.copy(config = Some(configPath)) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliTest.scala index 6b9d2ae828..cabdefb906 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/cli/CliTest.scala @@ -44,35 +44,35 @@ abstract class AbstractCliTest extends FunSuite { ) } - 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 + | extends App { + | pr( + | "h" + | ) + |} + |""".stripMargin val formatted = """|object a extends App { - | pr("h") - |} - |""".stripMargin - val customConfig = """ - |maxColumn = 2 - """.stripMargin + | pr("h") + |} + |""".stripMargin + val customConfig = """| + |maxColumn = 2 + | """.stripMargin val sbtOriginal = """|lazy val x = project - | lazy val y = project - | """.stripMargin + | lazy val y = project + | """.stripMargin val sbtExpected = """|lazy val x = - | project - |lazy val y = - | project - |""".stripMargin + | project + |lazy val y = + | project + |""".stripMargin def gimmeConfig(string: String): ScalafmtConfig = ScalafmtConfig .fromHoconString(string).get @@ -111,11 +111,11 @@ trait CliTestBehavior { val originalTmpFile = Files.createTempFile("prefix", ".scala") val originalTmpFile2 = Files.createTempFile("prefix2", ".scala") val scalafmtConfig = Files.createTempFile("scalafmtConfig", ".scala") - val config = s""" - |version="$version" - |maxColumn=7 - |style=IntelliJ - """.stripMargin + val config = s"""| + |version="$version" + |maxColumn=7 + |style=IntelliJ + | """.stripMargin Files.write(originalTmpFile, unformatted.getBytes) Files.write(originalTmpFile2, unformatted.getBytes) Files.write(scalafmtConfig, config.getBytes) @@ -153,11 +153,11 @@ trait CliTestBehavior { test(s"scalafmt --stdin --assume-filename: $label") { val scalafmtConfig = Files.createTempFile(".scalafmt", ".conf") - val config = s""" - |version="$version" - |maxColumn=7 - |style=IntelliJ - """.stripMargin + val config = s"""| + |version="$version" + |maxColumn=7 + |style=IntelliJ + | """.stripMargin Files.write(scalafmtConfig, config.getBytes) val args = Array( @@ -220,22 +220,22 @@ trait CliTestBehavior { test(s"handles .scala, .sbt, and .sc files: $label") { val input = string2dir( s"""|/foobar.scala - |object A { } - |/foo.sbt - |lazy val x = project - |/foo.sc - |lazy val x = project - |""".stripMargin + |object A { } + |/foo.sbt + |lazy val x = project + |/foo.sc + |lazy val x = project + |""".stripMargin ) val expected = s"""|/foo.sbt - |lazy val x = project - | - |/foo.sc - |lazy val x = project - | - |/foobar.scala - |object A {} - |""".stripMargin + |lazy val x = project + | + |/foo.sc + |lazy val x = project + | + |/foobar.scala + |object A {} + |""".stripMargin runArgs(Array( input.toString(), "--config-str", @@ -248,36 +248,36 @@ trait CliTestBehavior { test(s"excludefilters are respected: $label") { val input = string2dir( s"""|/foo.sbt - |lazy val x = project - | - |/target/FormatMe.scala - |object PleaseFormatMeOtherwiseIWillBeReallySad { } - | - |/target/nested1/DoNotFormatMe.scala - |object AAAAAAIgnoreME { } - | - |/target/nested1/nested2/DoNotFormatMeToo.scala - |object BBBBBBIgnoreME { } - | - |/target/nested3/DoNotFormatMe.scala - |object CIgnoreME { } - |""".stripMargin + |lazy val x = project + | + |/target/FormatMe.scala + |object PleaseFormatMeOtherwiseIWillBeReallySad { } + | + |/target/nested1/DoNotFormatMe.scala + |object AAAAAAIgnoreME { } + | + |/target/nested1/nested2/DoNotFormatMeToo.scala + |object BBBBBBIgnoreME { } + | + |/target/nested3/DoNotFormatMe.scala + |object CIgnoreME { } + |""".stripMargin ) val expected = s"""|/foo.sbt - |lazy val x = project - | - |/target/FormatMe.scala - |object PleaseFormatMeOtherwiseIWillBeReallySad {} - | - |/target/nested1/DoNotFormatMe.scala - |object AAAAAAIgnoreME { } - | - |/target/nested1/nested2/DoNotFormatMeToo.scala - |object BBBBBBIgnoreME { } - | - |/target/nested3/DoNotFormatMe.scala - |object CIgnoreME { } - |""".stripMargin + |lazy val x = project + | + |/target/FormatMe.scala + |object PleaseFormatMeOtherwiseIWillBeReallySad {} + | + |/target/nested1/DoNotFormatMe.scala + |object AAAAAAIgnoreME { } + | + |/target/nested1/nested2/DoNotFormatMeToo.scala + |object BBBBBBIgnoreME { } + | + |/target/nested3/DoNotFormatMe.scala + |object CIgnoreME { } + |""".stripMargin runArgs(Array( "--config-str", s"""{version="$version",style=IntelliJ}""", @@ -308,9 +308,9 @@ trait CliTestBehavior { test(s"scalafmt (no matching files) throws error: $label") { val scalafmtConfig: Path = Files.createTempFile(".scalafmt", ".conf") - val config: String = s""" - |version="$version" - """.stripMargin + val config: String = s"""| + |version="$version" + | """.stripMargin Files.write(scalafmtConfig, config.getBytes) val options = baseCliOptions.copy(config = Some(scalafmtConfig)) intercept[NoMatchingFiles.type] { Cli.run(options) } @@ -334,33 +334,33 @@ trait CliTestBehavior { test(s"scalafmt (no arg) read config from git repo: $label") { val input = string2dir( s"""|/foo.scala - |object FormatMe { - | val x = 1 - |} - |/target/foo.scala - |object A { } - | - |/.scalafmt.conf - |version = "$version" - |maxColumn = 2 - |project.excludeFilters = [target] - |""".stripMargin + |object FormatMe { + | val x = 1 + |} + |/target/foo.scala + |object A { } + | + |/.scalafmt.conf + |version = "$version" + |maxColumn = 2 + |project.excludeFilters = [target] + |""".stripMargin ) val expected = s"""|/.scalafmt.conf - |version = "$version" - |maxColumn = 2 - |project.excludeFilters = [target] - | - |/foo.scala - |object FormatMe { - | val x = - | 1 - |} - | - |/target/foo.scala - |object A { } - |""".stripMargin + |version = "$version" + |maxColumn = 2 + |project.excludeFilters = [target] + | + |/foo.scala + |object FormatMe { + | val x = + | 1 + |} + | + |/target/foo.scala + |object A { } + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } @@ -368,17 +368,17 @@ trait CliTestBehavior { noArgTest( string2dir( """|/foo.scala - |object FormatMe - |/foo.sc - |object FormatMe - |""".stripMargin + |object FormatMe + |/foo.sc + |object FormatMe + |""".stripMargin ), """|/foo.sc - |object FormatMe - | - |/foo.scala - |object FormatMe - |""".stripMargin, + |object FormatMe + | + |/foo.scala + |object FormatMe + |""".stripMargin, Seq(Array("--config-str", s"""{version="$version"}""")) ) } @@ -386,17 +386,17 @@ 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 x = + | 1 + |} + |""".stripMargin val input = string2dir( s"""|/nested/foo.scala - |$original - |/.scalafmt.conf - |version="$version" - |maxColumn = 2 - |""".stripMargin + |$original + |/.scalafmt.conf + |version="$version" + |maxColumn = 2 + |""".stripMargin ) val workingDir = input / "nested" val options: CliOptions = { @@ -410,18 +410,18 @@ trait CliTestBehavior { test(s"if project.includeFilters isn't modified (and files aren't passed manually), it should ONLY accept scala and sbt files: $label") { val root = string2dir( - s""" - |/scalafmt.conf - |style = default - |version="$version" - |/scalafile.scala - |$unformatted - |/scalatex.scalatex - |$unformatted - |/sbt.sbt - |$sbtOriginal - |/sbt.sbtfile - |$sbtOriginal""".stripMargin + s"""| + |/scalafmt.conf + |style = default + |version="$version" + |/scalafile.scala + |$unformatted + |/scalatex.scalatex + |$unformatted + |/sbt.sbt + |$sbtOriginal + |/sbt.sbtfile + |$sbtOriginal""".stripMargin ) val config = root / "scalafmt.conf" @@ -432,22 +432,22 @@ trait CliTestBehavior { assertNoDiff(dir2string(root / "scalafile.scala"), formatted) val sbtFormatted = """|lazy val x = project - |lazy val y = project - |""".stripMargin + |lazy val y = project + |""".stripMargin assertNoDiff(dir2string(root / "sbt.sbt"), sbtFormatted) } test(s"includeFilters are ignored for full paths but NOT test for passed directories: $label") { val root = string2dir( - s""" - |/inner1/file1.scala - |$unformatted - |/inner2/file2.scalahala - |$unformatted - |/inner3/file1.scala - |$unformatted - |/inner3/file2.scalahala - |$unformatted""".stripMargin + s"""| + |/inner1/file1.scala + |$unformatted + |/inner2/file2.scalahala + |$unformatted + |/inner3/file1.scala + |$unformatted + |/inner3/file2.scalahala + |$unformatted""".stripMargin ) val inner1 = root / "inner1" val inner2 = root / "inner2" @@ -467,15 +467,15 @@ trait CliTestBehavior { test(s"includeFilters are respected for full paths but NOT test for passed directories: $label") { val root = string2dir( - s""" - |/inner1/file1.scala - |$unformatted - |/inner2/file2.scalahala - |$unformatted - |/inner3/file1.scala - |$unformatted - |/inner3/file2.scalahala - |$unformatted""".stripMargin + s"""| + |/inner1/file1.scala + |$unformatted + |/inner2/file2.scalahala + |$unformatted + |/inner3/file1.scala + |$unformatted + |/inner3/file2.scalahala + |$unformatted""".stripMargin ) val inner1 = root / "inner1" val inner2 = root / "inner2" @@ -497,12 +497,12 @@ trait CliTestBehavior { test(s"--config accepts absolute paths: $label") { val root = string2dir( - s"""/scalafmt.conf - |version = "$version" - |style = intellij - |/foo.scala - |object A - """.stripMargin + s"""|/scalafmt.conf + |version = "$version" + |style = intellij + |/foo.scala + |object A + | """.stripMargin ) val config = (root / "scalafmt.conf").toString() val toFormat = (root / "foo.scala").toString() @@ -539,8 +539,8 @@ trait CliTestBehavior { test(s"parse error is formatted nicely: $label") { val input = """|/foo.scala - |object A { foo( } - |""".stripMargin + |object A { foo( } + |""".stripMargin noArgTest( string2dir(input), input, @@ -549,9 +549,9 @@ trait CliTestBehavior { assertOut = out => { assertContains( out, - s"""foo.scala:1: error:$dialectError illegal start of simple expression - |object A { foo( } - | ^""".stripMargin + s"""|foo.scala:1: error:$dialectError illegal start of simple expression + |object A { foo( } + | ^""".stripMargin ) }, Some(ExitCode.Ok) @@ -571,12 +571,12 @@ trait CliTestBehavior { test(s"--test failure prints out unified diff: $label") { val fooFile = "foo.scala" val input = s"""|/.scalafmt.conf - |onTestFailure = "To fix this ..." - |version = "$version" - | - |/$fooFile - |object A { } - |""".stripMargin + |onTestFailure = "To fix this ..." + |version = "$version" + | + |/$fooFile + |object A { } + |""".stripMargin val dir = string2dir(input) val fooPath = dir / fooFile noArgTest( @@ -587,12 +587,12 @@ trait CliTestBehavior { assertOut = out => { assertContains( out, - s"""b$fooPath - |@@ -1,1 +1,1 @@ - |-object A { } - |+object A {} - |error: --test failed - |To fix this ...""".stripMargin + s"""|b$fooPath + |@@ -1,1 +1,1 @@ + |-object A { } + |+object A {} + |error: --test failed + |To fix this ...""".stripMargin ) } ) @@ -600,8 +600,8 @@ trait CliTestBehavior { test(s"--test succeeds even with parse error: $label") { val input = """|/foo.scala - |object A { - |""".stripMargin + |object A { + |""".stripMargin noArgTest( string2dir(input), input, @@ -618,11 +618,11 @@ trait CliTestBehavior { test(s"--test fails with parse error if fatalWarnings=true: $label") { val input = s"""|/.scalafmt.conf - |runner.fatalWarnings = true - |version = "$version" - |/foo.scala - |object A { - |""".stripMargin + |runner.fatalWarnings = true + |version = "$version" + |/foo.scala + |object A { + |""".stripMargin noArgTest( string2dir(input), input, @@ -640,11 +640,11 @@ trait CliTestBehavior { test(s"exception is thrown on invalid .scalafmt.conf: $label") { val input = s"""/.scalafmt.conf - |version="$version" - |blah = intellij - |/foo.scala - |object A {} - """.stripMargin + |version="$version" + |blah = intellij + |/foo.scala + |object A {} + | """.stripMargin noArgTest( string2dir(input), input, @@ -674,12 +674,12 @@ trait CliTestBehavior { val expected = "This message should be shown" val unexpected = "This message should not be shown" val input = s"""|/.scalafmt.conf - |onTestFailure = "$unexpected" - |version = "$version" - | - |/foo.scala - |object A { } - |""".stripMargin + |onTestFailure = "$unexpected" + |version = "$version" + | + |/foo.scala + |object A { } + |""".stripMargin noArgTest( string2dir(input), input, @@ -696,17 +696,17 @@ trait CliTestBehavior { test(s"--list enable scalafmt to output a list of unformatted files with ExitCode.TestError: $label") { val input = s"""|/.scalafmt.conf - |version = "$version" - | - |/bar.scala - |object A { } - | - |/baz.scala - |object A {} - | - |/dir/foo.scala - |object A { } - |""".stripMargin + |version = "$version" + | + |/bar.scala + |object A { } + | + |/baz.scala + |object A {} + | + |/dir/foo.scala + |object A { } + |""".stripMargin val dir = string2dir(input) noArgTest( dir, @@ -730,14 +730,14 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"path-error") { val input = s"""|/.scalafmt.conf - |version = "${stableVersion}" - |project.excludePaths = [ - | "glob:**/src/main/scala/besom/rpc/**.scala", - | "foo.scala" - |] - |/foo.scala - |object A { foo( } - |""".stripMargin + |version = "${stableVersion}" + |project.excludePaths = [ + | "glob:**/src/main/scala/besom/rpc/**.scala", + | "foo.scala" + |] + |/foo.scala + |object A { foo( } + |""".stripMargin noArgTest( string2dir(input), @@ -757,13 +757,13 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"regex-error") { val input = s"""|/.scalafmt.conf - |version = "${stableVersion}" - |project.excludeFilters = [ - | ".*foo(" - |] - |/foo.scala - |object A { foo( } - |""".stripMargin + |version = "${stableVersion}" + |project.excludeFilters = [ + | ".*foo(" + |] + |/foo.scala + |object A { foo( } + |""".stripMargin noArgTest( string2dir(input), @@ -774,9 +774,9 @@ class CliTest extends AbstractCliTest with CliTestBehavior { assertContains( out, """|Illegal regex in configuration: .*foo( - |reason: Unclosed group near index 6 - |.*foo( - |""".stripMargin + |reason: Unclosed group near index 6 + |.*foo( + |""".stripMargin ) }, Some(ExitCode.UnexpectedError) @@ -786,8 +786,8 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test("Fail if .scalafmt.conf is missing.") { val input = s"""|/foo.scala - |object A {} - |""".stripMargin + |object A {} + |""".stripMargin noArgTest( string2dir(input), input, @@ -807,11 +807,11 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test("Fail if `version` setting is missing.") { val input = s"""|/.scalafmt.conf - |maxColumn = 10 - | - |/foo.scala - |object A {} - |""".stripMargin + |maxColumn = 10 + | + |/foo.scala + |object A {} + |""".stripMargin noArgTest( string2dir(input), input, @@ -860,102 +860,102 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"scalafmt use includePaths") { val input = string2dir( s"""|/bar.scala - |object FormatMe { - | val x = 1 - |} - | - |/target/foo.scala - |object A { } - | - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { includePaths = ["glob:**/bar.scala"] } - |""".stripMargin + |object FormatMe { + | val x = 1 + |} + | + |/target/foo.scala + |object A { } + | + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 2 + |project { includePaths = ["glob:**/bar.scala"] } + |""".stripMargin ) val expected = s"""|/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { includePaths = ["glob:**/bar.scala"] } - | - |/bar.scala - |object FormatMe { - | val x = - | 1 - |} - | - |/target/foo.scala - |object A { } - |""".stripMargin + |version = $stableVersion + |maxColumn = 2 + |project { includePaths = ["glob:**/bar.scala"] } + | + |/bar.scala + |object FormatMe { + | val x = + | 1 + |} + | + |/target/foo.scala + |object A { } + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } test(s"scalafmt use excludePaths") { val input = string2dir( s"""|/foo.scala - |object FormatMe { - | val x = 1 - |} - | - |/target/foo.scala - |object A { } - | - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { excludePaths = ["glob:**target**"] } - |""".stripMargin + |object FormatMe { + | val x = 1 + |} + | + |/target/foo.scala + |object A { } + | + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 2 + |project { excludePaths = ["glob:**target**"] } + |""".stripMargin ) val expected = s"""|/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { excludePaths = ["glob:**target**"] } - | - |/foo.scala - |object FormatMe { - | val x = - | 1 - |} - | - |/target/foo.scala - |object A { } - |""".stripMargin + |version = $stableVersion + |maxColumn = 2 + |project { excludePaths = ["glob:**target**"] } + | + |/foo.scala + |object FormatMe { + | val x = + | 1 + |} + | + |/target/foo.scala + |object A { } + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } test(s"scalafmt: includeFilters overrides default includePaths") { val input = string2dir( s"""|/bar.scala - |object FormatMe { - | val x = 1 - |} - | - |/target/foo.scala - |object A { } - | - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { includeFilters = ["bar"] } - |""".stripMargin + |object FormatMe { + | val x = 1 + |} + | + |/target/foo.scala + |object A { } + | + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 2 + |project { includeFilters = ["bar"] } + |""".stripMargin ) val expected = s"""|/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { includeFilters = ["bar"] } - | - |/bar.scala - |object FormatMe { - | val x = - | 1 - |} - | - |/target/foo.scala - |object A { } - |""".stripMargin + |version = $stableVersion + |maxColumn = 2 + |project { includeFilters = ["bar"] } + | + |/bar.scala + |object FormatMe { + | val x = + | 1 + |} + | + |/target/foo.scala + |object A { } + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } @@ -964,79 +964,79 @@ class CliTest extends AbstractCliTest with CliTestBehavior { .mkString("[\"", "\", \"", "\"]") val input = string2dir( s"""|/bar.scala - |object FormatMe { - | val x = 1 - |} - | - |/target/foo.scala - |object A { } - | - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { - | includePaths = $defaultIncludePathsJson - | includeFilters = ["bar"] - |} - |""".stripMargin + |object FormatMe { + | val x = 1 + |} + | + |/target/foo.scala + |object A { } + | + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 2 + |project { + | includePaths = $defaultIncludePathsJson + | includeFilters = ["bar"] + |} + |""".stripMargin ) val expected = s"""|/.scalafmt.conf - |version = $stableVersion - |maxColumn = 2 - |project { - | includePaths = $defaultIncludePathsJson - | includeFilters = ["bar"] - |} - | - |/bar.scala - |object FormatMe { - | val x = - | 1 - |} - | - |/target/foo.scala - |object A {} - |""".stripMargin + |version = $stableVersion + |maxColumn = 2 + |project { + | includePaths = $defaultIncludePathsJson + | includeFilters = ["bar"] + |} + | + |/bar.scala + |object FormatMe { + | val x = + | 1 + |} + | + |/target/foo.scala + |object A {} + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } test(s"handles .md files when present in includePaths") { val input = string2dir( s"""|/foobar.md - |# Hello - |Example usage 1 with long spaced line - |```scala mdoc - |val x = 42 - |``` - |Example usage 2 - |```java - |val x = 42 - |``` - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 8 - |project.includePaths."+" = ["glob:**.md"] - |""".stripMargin + |# Hello + |Example usage 1 with long spaced line + |```scala mdoc + |val x = 42 + |``` + |Example usage 2 + |```java + |val x = 42 + |``` + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 8 + |project.includePaths."+" = ["glob:**.md"] + |""".stripMargin ) val expected = s"""| - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 8 - |project.includePaths."+" = ["glob:**.md"] - | - |/foobar.md - |# Hello - |Example usage 1 with long spaced line - |```scala mdoc - |val x = - | 42 - |``` - |Example usage 2 - |```java - |val x = 42 - |``` - |""".stripMargin + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 8 + |project.includePaths."+" = ["glob:**.md"] + | + |/foobar.md + |# Hello + |Example usage 1 with long spaced line + |```scala mdoc + |val x = + | 42 + |``` + |Example usage 2 + |```java + |val x = 42 + |``` + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } @@ -1044,26 +1044,26 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"ignores .md files if not present in includePaths") { val input = string2dir( s"""|/foobar.md - |# Hello - |Example usage 1 - |```scala mdoc - |val x = 42 - |``` - |/.scalafmt.conf - |version = $stableVersion - |""".stripMargin + |# Hello + |Example usage 1 + |```scala mdoc + |val x = 42 + |``` + |/.scalafmt.conf + |version = $stableVersion + |""".stripMargin ) val expected = s"""| - |/.scalafmt.conf - |version = $stableVersion - | - |/foobar.md - |# Hello - |Example usage 1 - |```scala mdoc - |val x = 42 - |``` - |""".stripMargin + |/.scalafmt.conf + |version = $stableVersion + | + |/foobar.md + |# Hello + |Example usage 1 + |```scala mdoc + |val x = 42 + |``` + |""".stripMargin try { noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) @@ -1074,30 +1074,30 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"handles .md with normal comment that contains a nested fence") { val input = string2dir( s"""|/foobar.md - | Intro - |```scala mdoc - |object A { - | /* - | * ```scala mdoc - | * val example = "text" - | * ``` - | */ - | } - |``` - |""".stripMargin + | Intro + |```scala mdoc + |object A { + | /* + | * ```scala mdoc + | * val example = "text" + | * ``` + | */ + | } + |``` + |""".stripMargin ) val expected = s"""|/foobar.md - | Intro - |```scala mdoc - |object A { - | /* - | * ```scala mdoc - | * val example = "text" - | * ``` - | */ - |} - |``` - |""".stripMargin + | Intro + |```scala mdoc + |object A { + | /* + | * ```scala mdoc + | * val example = "text" + | * ``` + | */ + |} + |``` + |""".stripMargin runArgs(Array( input.toString(), "--config-str", @@ -1111,18 +1111,18 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"does apply to .md files with indented fenced content ") { val input = string2dir( s"""|/foobar2.md - | Intro text: - | ```scala mdoc - | object A { } - | ``` - |""".stripMargin + | Intro text: + | ```scala mdoc + | object A { } + | ``` + |""".stripMargin ) val expected = s"""|/foobar2.md - | Intro text: - | ```scala mdoc - | object A {} - | ``` - |""".stripMargin + | Intro text: + | ```scala mdoc + | object A {} + | ``` + |""".stripMargin runArgs(Array( input.toString(), "--config-str", @@ -1136,28 +1136,28 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"does not format nested fences when not inside a Scala comment") { val input = string2dir( s"""|/foobar.md - |```scala mdoc - |object A { - | /* - |```scala mdoc - | val example = "text" - |``` - | */ - | } - |``` - |""".stripMargin + |```scala mdoc + |object A { + | /* + |```scala mdoc + | val example = "text" + |``` + | */ + | } + |``` + |""".stripMargin ) val expected = s"""|/foobar.md - |```scala mdoc - |object A { - | /* - |```scala mdoc - | val example = "text" - |``` - | */ - | } - |``` - |""".stripMargin + |```scala mdoc + |object A { + | /* + |```scala mdoc + | val example = "text" + |``` + | */ + | } + |``` + |""".stripMargin runArgs( Array( input.toString(), @@ -1173,39 +1173,39 @@ class CliTest extends AbstractCliTest with CliTestBehavior { test(s"handles .md fences with uneven backticks") { val input = string2dir( s"""|/foobar.md - |# Hello - |Example usage 1 with long spaced line - |```scala mdoc - |val x = 42 - |````` - |Example usage 2 - |```java - |val x = 42 - |``` - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 8 - |project.includePaths."+" = ["glob:**.md"] - |""".stripMargin + |# Hello + |Example usage 1 with long spaced line + |```scala mdoc + |val x = 42 + |````` + |Example usage 2 + |```java + |val x = 42 + |``` + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 8 + |project.includePaths."+" = ["glob:**.md"] + |""".stripMargin ) val expected = s"""| - |/.scalafmt.conf - |version = $stableVersion - |maxColumn = 8 - |project.includePaths."+" = ["glob:**.md"] - | - |/foobar.md - |# Hello - |Example usage 1 with long spaced line - |```scala mdoc - |val x = - | 42 - |````` - |Example usage 2 - |```java - |val x = 42 - |``` - |""".stripMargin + |/.scalafmt.conf + |version = $stableVersion + |maxColumn = 8 + |project.includePaths."+" = ["glob:**.md"] + | + |/foobar.md + |# Hello + |Example usage 1 with long spaced line + |```scala mdoc + |val x = + | 42 + |````` + |Example usage 2 + |```java + |val x = 42 + |``` + |""".stripMargin noArgTest(input, expected, Seq(Array.empty[String], Array("--mode", "diff"))) } @@ -1214,9 +1214,9 @@ class CliTest extends AbstractCliTest with CliTestBehavior { val out = new ByteArrayOutputStream() val err = new ByteArrayOutputStream() val codeNoEol = """|object FormatMe { - | val x = - | 1 - |}""".stripMargin + | val x = + | 1 + |}""".stripMargin Console.withOut(out) { Console.withErr(err) { val options = getConfig(Array("--stdin", "--test")) @@ -1234,12 +1234,12 @@ class CliTest extends AbstractCliTest with CliTestBehavior { assertEquals(CliTest.stripCR(out.toString), "error: --test failed\n") assertEquals( CliTest.stripCR(err.toString), - """--- astdin.scala - |+++ bstdin.scala - |@@ -4,1 +4,2 @@ - | } - |+ - |""".stripMargin + """|--- astdin.scala + |+++ bstdin.scala + |@@ -4,1 +4,2 @@ + | } + |+ + |""".stripMargin ) } diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/cli/FileTestOps.scala b/scalafmt-tests/src/test/scala/org/scalafmt/cli/FileTestOps.scala index 6f2c19916a..3c77269fa7 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/cli/FileTestOps.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/cli/FileTestOps.scala @@ -37,7 +37,7 @@ object FileTestOps { val prefix = rootPath.toString FileOps.listFiles(rootPath).sortBy(_.toString).map { path => s"""|${path.toString.stripPrefix(prefix)} - |${FileOps.readFile(path)}""".stripMargin + |${FileOps.readFile(path)}""".stripMargin }.mkString("\n").replace(File.separator, "/") // ensure original separators } diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/config/ScalafmtConfigTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/config/ScalafmtConfigTest.scala index 6fe7880876..38a5be8c87 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/config/ScalafmtConfigTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/config/ScalafmtConfigTest.scala @@ -6,13 +6,13 @@ class ScalafmtConfigTest extends FunSuite { test("project.matcher") { val config = ScalafmtConfig.fromHoconString( - """ - |project.excludeFilters = [ - | "scalafmt-benchmarks/src/resources" - | "/sbt-test/" - | "bin/issue" - |] - """.stripMargin + """| + |project.excludeFilters = [ + | "scalafmt-benchmarks/src/resources" + | "/sbt-test/" + | "bin/issue" + |] + | """.stripMargin ).get assert(config.project.matcher.matches("qux/Kazbar.scala")) assert(!config.project.matcher.matches("foo/sbt-test/src/main")) @@ -29,7 +29,7 @@ class ScalafmtConfigTest extends FunSuite { | newlines.topLevelBodyIfMinStatements = [] | } |} - """.stripMargin + | """.stripMargin ).get val nlCfg1 = config.getConfigFor("/x/src/main/scala/foo.scala").get.newlines val nlCfg2 = config.getConfigFor("/x/src/test/scala/bar.scala").get.newlines @@ -44,10 +44,10 @@ class ScalafmtConfigTest extends FunSuite { test("align preset no override") { val config = ScalafmtConfig.fromHoconString( - """ - |align = none - |align.stripMargin = true - """.stripMargin + """| + |align = none + |align.stripMargin = true + | """.stripMargin ).get // none was ignored assertEquals(config.align, Align(stripMargin = true)) @@ -65,26 +65,26 @@ class ScalafmtConfigTest extends FunSuite { test("dialect override") { val config1 = ScalafmtConfig.fromHoconString( - """ - |runner.dialect = scala213 - |""".stripMargin + """| + |runner.dialect = scala213 + |""".stripMargin ).get assert(!config1.runner.getDialect.allowToplevelTerms) val config2 = ScalafmtConfig.fromHoconString( - """ - |runner.dialectOverride.allowToplevelTerms = true - |runner.dialect = scala213 - |""".stripMargin + """| + |runner.dialectOverride.allowToplevelTerms = true + |runner.dialect = scala213 + |""".stripMargin ).get assert(config2.runner.getDialect.allowToplevelTerms) } test("hasRewriteRules-and-withoutRewriteRules trailingCommas") { val config1 = ScalafmtConfig.fromHoconString( - """ - |runner.dialect = scala213 - |rewrite.trailingCommas = never - |""".stripMargin + """| + |runner.dialect = scala213 + |rewrite.trailingCommas = never + |""".stripMargin ).get assert(config1.hasRewrites) val config2 = config1.withoutRewrites @@ -93,11 +93,11 @@ class ScalafmtConfigTest extends FunSuite { test("hasRewriteRules-and-withoutRewriteRules docstrings") { val config1 = ScalafmtConfig.fromHoconString( - """ - |runner.dialect = scala213 - |rewrite.trailingCommas = keep - |docstrings.removeEmpty = true - |""".stripMargin + """| + |runner.dialect = scala213 + |rewrite.trailingCommas = keep + |docstrings.removeEmpty = true + |""".stripMargin ).get assert(config1.hasRewrites) val config2 = config1.withoutRewrites diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala index 4ebded1f21..8a0abc0884 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala @@ -86,9 +86,9 @@ trait HasTests extends FormatAssertions { def loadStyle(cfg: String, base: ScalafmtConfig): ScalafmtConfig = ScalafmtConfig.fromHoconString(cfg, base).getOrRecover { c => throw new IllegalArgumentException( - s"""Failed to parse filename $filename: - |$cfg - |$c""".stripMargin + s"""|Failed to parse filename $filename: + |$cfg + |$c""".stripMargin ) } val style: ScalafmtConfig = loadStyle( diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/Report.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/Report.scala index b048fc7c69..733b76670c 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/Report.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/Report.scala @@ -51,11 +51,11 @@ object Report { def explanation = div( p( - """Formatting output from scalafmt's test suite. - |The formatter uses Dijkstra's shortest path to determine the - |formatting with the "cheapest" cost. The red regions are - |tokens the formatter visits often. - """.stripMargin + """|Formatting output from scalafmt's test suite. + |The formatter uses Dijkstra's shortest path to determine the + |formatting with the "cheapest" cost. The red regions are + |tokens the formatter visits often. + | """.stripMargin ), ul( li("Declaration arguments: bin packed"), diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/StyleMapTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/StyleMapTest.scala index 6291f0b1f9..005acfa482 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/StyleMapTest.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/StyleMapTest.scala @@ -10,12 +10,12 @@ 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, @@ -29,11 +29,12 @@ class StyleMapTest extends FunSuite { } test("align.tokens.+") { - val code = """object a { - | // scalafmt: { align.tokens."+" = [{ code="=", owner=".*" }] } - | println(1) - |} - """.stripMargin.parse[Source].get + val code = + """|object a { + | // scalafmt: { align.tokens."+" = [{ code="=", owner=".*" }] } + | println(1) + |} + | """.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 @@ -67,11 +68,12 @@ class StyleMapTest extends FunSuite { } test("newlines.implicitParamListModifierForce") { - val code = """object a { - | // scalafmt: { newlines.implicitParamListModifierForce = [after] } - | println(1) - |} - """.stripMargin.parse[Source].get + val code = + """|object a { + | // scalafmt: { newlines.implicitParamListModifierForce = [after] } + | println(1) + |} + |""".stripMargin.parse[Source].get val formatOps = new FormatOps( code, ScalafmtConfig(newlines = @@ -113,13 +115,13 @@ 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.enabled)) /*