Skip to content

Commit d76cb7c

Browse files
committed
scalafmt: align strip margins
1 parent 8c3ec5e commit d76cb7c

File tree

26 files changed

+872
-867
lines changed

26 files changed

+872
-867
lines changed

.scalafmt.conf

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project {
1010
}
1111
align {
1212
preset = none
13+
stripMargin = true
1314
}
1415
newlines {
1516
avoidForSimpleOverflow = [punct, slc, tooLong]

readme/src/main/scala/org/scalafmt/readme/Readme.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ object Readme {
5454
val expressions = s"{$code}".parse[Stat].get.asInstanceOf[Term.Block].stats
5555
val evaluated = eval[Any](code)
5656
val output = evaluated match {
57-
case s: String => s"""
58-
|"$s"""".stripMargin
57+
case s: String => s"""|
58+
|"$s"""".stripMargin
5959
case x => x.toString
6060
}
61-
val result =
62-
s"""${expressions.map(x => s"scala> ${x.toString().trim}").mkString("\n")}
63-
|res0: ${evaluated.getClass.getName} = $output
64-
|""".stripMargin
61+
val result = s"""|${expressions.map(x => s"scala> ${x.toString().trim}")
62+
.mkString("\n")}
63+
|res0: ${evaluated.getClass.getName} = $output
64+
|""".stripMargin
6565
hl.scala(result)
6666
}
6767

scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala

+21-21
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ object Cli {
101101
private def findRunner(options: CliOptions): MaybeRunner = options.hoconOpt
102102
.fold[MaybeRunner] {
103103
Left(
104-
s"""error: missing Scalafmt configuration file.
105-
|Consider creating '${options.getProposedConfigFile}'
106-
|with the following (other parameters may also be required):
107-
|${getProposedConfigVersion(options)}
108-
|""".stripMargin
104+
s"""|error: missing Scalafmt configuration file.
105+
|Consider creating '${options.getProposedConfigFile}'
106+
|with the following (other parameters may also be required):
107+
|${getProposedConfigVersion(options)}
108+
|""".stripMargin
109109
)
110110
} {
111111
// Run format using
@@ -119,10 +119,10 @@ object Cli {
119119
case _ => "--config-str option"
120120
}
121121
Left(
122-
s"""error: missing Scalafmt version.
123-
|Consider adding the following to $where:
124-
|${getProposedConfigVersion(options)}
125-
|""".stripMargin
122+
s"""|error: missing Scalafmt version.
123+
|Consider adding the following to $where:
124+
|${getProposedConfigVersion(options)}
125+
|""".stripMargin
126126
)
127127
} {
128128
case Left(error) => Left(s"error: invalid configuration: ${error}")
@@ -131,18 +131,18 @@ object Cli {
131131
Right(ScalafmtCoreRunner)
132132
case Right(v) if isNativeImage =>
133133
Left(
134-
s"""error: invalid Scalafmt version.
135-
|
136-
|This Scalafmt installation has version '$stableVersion' and the version configured in '${options
137-
.configPath}' is '$v'.
138-
|To fix this problem, add the following line to .scalafmt.conf:
139-
|```
140-
|version = $stableVersion
141-
|```
142-
|
143-
|NOTE: this error happens only when running a native Scalafmt binary.
144-
|Scalafmt automatically installs and invokes the correct version of Scalafmt when running on the JVM.
145-
|""".stripMargin
134+
s"""|error: invalid Scalafmt version.
135+
|
136+
|This Scalafmt installation has version '$stableVersion' and the version configured in '${options
137+
.configPath}' is '$v'.
138+
|To fix this problem, add the following line to .scalafmt.conf:
139+
|```
140+
|version = $stableVersion
141+
|```
142+
|
143+
|NOTE: this error happens only when running a native Scalafmt binary.
144+
|Scalafmt automatically installs and invokes the correct version of Scalafmt when running on the JVM.
145+
|""".stripMargin
146146
)
147147
case Right(v) =>
148148
options.common.debug.println(s"Using dynamic runner [$v]")

scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala

+31-30
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ object CliArgParser {
1212

1313
val usageExamples: String =
1414
"""|scalafmt # Format all files in the current project, configuration is determined in this order:
15-
| # 1. .scalafmt.conf file in current directory
16-
| # 2. .scalafmt.conf inside root directory of current git repo
17-
| # 3. no configuration, default style
18-
|scalafmt --test # throw exception on mis-formatted files, won't write to files.
19-
|scalafmt --mode diff # Format all files that were edited in git diff against master branch.
20-
|scalafmt --mode changed # Format files listed in `git status` (latest changes against previous commit.
21-
|scalafmt --diff-branch 2.x # same as --diff, except against branch 2.x
22-
|scalafmt --stdin # read from stdin (doesn't imply --stdout)
23-
|scalafmt --stdin --assume-filename foo.sbt < foo.sbt # required when using --stdin to format .sbt files.
24-
|scalafmt Code1.scala A.scala # write formatted contents to file.
25-
|scalafmt --stdout Code.scala # print formatted contents to stdout.
26-
|scalafmt --exclude target # format all files in directory excluding target
27-
|scalafmt --config .scalafmt.conf # read custom style from file.
28-
|scalafmt --config-str "style=IntelliJ" # define custom style as a flag, must be quoted."""
15+
| # 1. .scalafmt.conf file in current directory
16+
| # 2. .scalafmt.conf inside root directory of current git repo
17+
| # 3. no configuration, default style
18+
|scalafmt --test # throw exception on mis-formatted files, won't write to files.
19+
|scalafmt --mode diff # Format all files that were edited in git diff against master branch.
20+
|scalafmt --mode changed # Format files listed in `git status` (latest changes against previous commit.
21+
|scalafmt --diff-branch 2.x # same as --diff, except against branch 2.x
22+
|scalafmt --stdin # read from stdin (doesn't imply --stdout)
23+
|scalafmt --stdin --assume-filename foo.sbt < foo.sbt # required when using --stdin to format .sbt files.
24+
|scalafmt Code1.scala A.scala # write formatted contents to file.
25+
|scalafmt --stdout Code.scala # print formatted contents to stdout.
26+
|scalafmt --exclude target # format all files in directory excluding target
27+
|scalafmt --config .scalafmt.conf # read custom style from file.
28+
|scalafmt --config-str "style=IntelliJ" # define custom style as a flag, must be quoted."""
2929
.stripMargin
3030

3131
val scoptParser: OptionParser[CliOptions] =
@@ -53,9 +53,9 @@ object CliArgParser {
5353
arg[Path]("<file>...").optional().unbounded().action((file, c) =>
5454
c.addFile(file)
5555
).text(
56-
"""file, or directory (in which all *.scala files are to be formatted);
57-
|if starts with '@', refers to path listing files to be formatted
58-
|(with "@-" referring to standard input as a special case)"""
56+
"""|file, or directory (in which all *.scala files are to be formatted);
57+
|if starts with '@', refers to path listing files to be formatted
58+
|(with "@-" referring to standard input as a special case)"""
5959
.stripMargin
6060
)
6161

@@ -99,20 +99,20 @@ object CliArgParser {
9999
writeMode(c, WriteMode.Test).copy(error = true, check = true)
100100
).text("test for mis-formatted code only, exits with status 1 on first failure.")
101101
opt[FileFetchMode]("mode").action((m, c) => c.copy(mode = Option(m))).text(
102-
s"""Sets the files to be formatted fetching mode.
103-
|Options:
104-
|${FileFetchMode.help}
105-
|""".stripMargin
102+
s"""|Sets the files to be formatted fetching mode.
103+
|Options:
104+
|${FileFetchMode.help}
105+
|""".stripMargin
106106
)
107107
opt[Unit]("diff")
108108
.action((_, c) => c.copy(mode = Option(DiffFiles("master")))).text(
109-
s"""Format files listed in `git diff` against master.
110-
|Deprecated: use --mode diff instead""".stripMargin
109+
s"""|Format files listed in `git diff` against master.
110+
|Deprecated: use --mode diff instead""".stripMargin
111111
)
112112
opt[String]("diff-branch")
113113
.action((branch, c) => c.copy(mode = Option(DiffFiles(branch)))).text(
114-
s"""Format files listed in `git diff` against given git ref.
115-
|Deprecated: use --mode diff-ref=<ref> instead""".stripMargin
114+
s"""|Format files listed in `git diff` against given git ref.
115+
|Deprecated: use --mode diff-ref=<ref> instead""".stripMargin
116116
)
117117
opt[Unit]("build-info").action((_, _) => { println(buildInfo); sys.exit })
118118
.text("prints build information")
@@ -132,9 +132,9 @@ object CliArgParser {
132132

133133
note(
134134
s"""|Examples:
135-
|$usageExamples
136-
|Please file bugs to https://github.com/scalameta/scalafmt/issues
137-
""".stripMargin
135+
|$usageExamples
136+
|Please file bugs to https://github.com/scalameta/scalafmt/issues
137+
|""".stripMargin
138138
)
139139

140140
checkConfig { c =>
@@ -143,8 +143,9 @@ object CliArgParser {
143143
else success
144144
}
145145
}
146-
def buildInfo = s"""build commit: ${Versions.commit}
147-
|build time: ${new Date(Versions.timestamp.toLong)}""".stripMargin
146+
def buildInfo =
147+
s"""|build commit: ${Versions.commit}
148+
|build time: ${new Date(Versions.timestamp.toLong)}""".stripMargin
148149

149150
private def writeMode(c: CliOptions, writeMode: WriteMode): CliOptions = c
150151
.writeModeOpt.fold { c.copy(writeModeOpt = Some(writeMode)) } { x =>

scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ object Error {
4141

4242
case class FormatterChangedAST(diff: String, output: String)
4343
extends Error(
44-
s"""Formatter changed AST
45-
|=====================
46-
|$diff
47-
|=====================
48-
|${output.linesIterator.toVector.take(10).mkString("\n")}
49-
|=====================
50-
|Formatter changed AST
51-
""".stripMargin
44+
s"""|Formatter changed AST
45+
|=====================
46+
|$diff
47+
|=====================
48+
|${output.linesIterator.toVector.take(10).mkString("\n")}
49+
|=====================
50+
|Formatter changed AST
51+
|""".stripMargin
5252
)
5353

5454
case class FormatterOutputDoesNotParse(msg: String, line: Int)
5555
extends Error("Formatter output does not parse:\n" + msg)
5656

5757
case class UnexpectedTree[Expected <: Tree: ClassTag](obtained: Tree)
5858
extends Error(
59-
s"""Expected: ${classTag[Expected].runtimeClass.getName}
60-
|Obtained: ${log(obtained)}""".stripMargin
59+
s"""|Expected: ${classTag[Expected].runtimeClass.getName}
60+
|Obtained: ${log(obtained)}""".stripMargin
6161
)
6262

6363
case class CantFormatFile(msg: String)

scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ object NamedDialect {
3939

4040
def getUnknownError = {
4141
val knownStr = known.map(_.name).mkString(",")
42-
s"""Default dialect is deprecated; use explicit: [$knownStr]
43-
|Also see https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects"
44-
|""".stripMargin
42+
s"""|Default dialect is deprecated; use explicit: [$knownStr]
43+
|Also see https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects"
44+
|""".stripMargin
4545
}
4646

4747
implicit val codec: ConfCodecEx[NamedDialect] = ReaderUtil

scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ object ProjectFiles {
8585
case e: java.util.regex.PatternSyntaxException =>
8686
throw new ScalafmtConfigException(
8787
s"""|Illegal regex in configuration: $regex
88-
|reason: ${e.getMessage()}""".stripMargin
88+
|reason: ${e.getMessage()}""".stripMargin
8989
)
9090
}
9191

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,17 @@ private class BestFirstSearch private (
290290
val tok = tokens(deepestYet.depth)
291291
val splitsAfterPolicy = deepestYet.policy
292292
.execute(Decision(tok, nextSplits))
293-
val msg = s"""UNABLE TO FORMAT,
294-
|tok=$tok
295-
|toks.length=${tokens.length}
296-
|deepestYet.length=${deepestYet.depth}
297-
|policies=${deepestYet.policy.policies}
298-
|nextSplits=$nextSplits
299-
|splitsAfterPolicy=$splitsAfterPolicy""".stripMargin
293+
val msg = s"""|UNABLE TO FORMAT,
294+
|tok=$tok
295+
|toks.length=${tokens.length}
296+
|deepestYet.length=${deepestYet.depth}
297+
|policies=${deepestYet.policy.policies}
298+
|nextSplits=$nextSplits
299+
|splitsAfterPolicy=$splitsAfterPolicy""".stripMargin
300300
if (runner.debug) {
301301
logger.debug(
302-
s"""Failed to format
303-
|$msg""".stripMargin
302+
s"""|Failed to format
303+
|$msg""".stripMargin
304304
)
305305
}
306306
complete(deepestYet)

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,11 @@ class FormatOps(
13411341
case _ if orNil => Nil
13421342
case t =>
13431343
logger.debug(
1344-
s"""getApplyArgs: unknown tree
1345-
|Tree: ${log(t)}
1346-
|Parent: ${log(t.parent)}
1347-
|GrandParent: ${log(t.parent.flatMap(_.parent))}
1348-
|""".stripMargin
1344+
s"""|getApplyArgs: unknown tree
1345+
|Tree: ${log(t)}
1346+
|Parent: ${log(t.parent)}
1347+
|GrandParent: ${log(t.parent.flatMap(_.parent))}
1348+
|""".stripMargin
13491349
)
13501350
throw UnexpectedTree[Member.SyntaxValuesClause](t)
13511351
}

scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/Patch.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ object Patch {
4040
case (add: Add, _: Remove) => add.copy(keepTok = false)
4141
case (rem: Remove, _: Remove) => rem
4242
case _ => sys.error(
43-
s"""Can't merge token patches:
44-
|1. $a
45-
|2. $b""".stripMargin
43+
s"""|Can't merge token patches:
44+
|1. $a
45+
|2. $b""".stripMargin
4646
)
4747
}
4848

scalafmt-core/shared/src/main/scala/org/scalafmt/util/LoggerOps.scala

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ object LoggerOps {
2828
}
2929
def log(split: Split): String = s"$split"
3030

31-
def log(formatToken: FormatToken): String = s"""${log(formatToken.left)}
32-
|${log(formatToken.between: _*)}
33-
|${log(formatToken.right)}""".stripMargin
31+
def log(formatToken: FormatToken): String =
32+
s"""|${log(formatToken.left)}
33+
|${log(formatToken.between: _*)}
34+
|${log(formatToken.right)}""".stripMargin
3435

3536
def log2(formatToken: FormatToken): String = formatToken.toString
3637

@@ -52,11 +53,11 @@ object LoggerOps {
5253
def log(t: Tree, tokensOnly: Boolean): String = {
5354
val tokens = s"TOKENS: ${t.tokens.map(x => reveal(x.syntax)).mkString(",")}"
5455
if (tokensOnly) tokens
55-
else s"""TYPE: ${t.getClass.getName.stripPrefix("scala.meta.")}
56-
|SOURCE: $t
57-
|STRUCTURE: ${t.show[Structure]}
58-
|$tokens
59-
|""".stripMargin
56+
else s"""|TYPE: ${t.getClass.getName.stripPrefix("scala.meta.")}
57+
|SOURCE: $t
58+
|STRUCTURE: ${t.show[Structure]}
59+
|$tokens
60+
|""".stripMargin
6061
}
6162

6263
def log(t: Option[Tree]): String = log(t, false)

0 commit comments

Comments
 (0)