Skip to content

Commit

Permalink
scalafmt: expand RedundantBraces
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Apr 1, 2024
1 parent d32b796 commit 539d461
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ rewrite {
["org\\..*"]
]
}
redundantBraces {
ifElseExpressions = true
stringInterpolation = true
}
sortModifiers.preset = styleGuide
}
align {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ inThisBuild(
publish / skip := true

val scalafmtVersion = "3.8.1"
onLoadMessage := s"Welcome to sbt-scalafmt ${version.value} (scalafmt ${scalafmtVersion})"
onLoadMessage := s"Welcome to sbt-scalafmt ${version.value} (scalafmt $scalafmtVersion)"

lazy val plugin = project
.enablePlugins(SbtPlugin)
Expand Down
23 changes: 10 additions & 13 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ object ScalafmtPlugin extends AutoPlugin {

private val scalaConfig =
scalafmtConfig.map { f =>
if (f.exists()) {
if (f.exists())
f.toPath
} else {
else
throw messageException(s"File does not exist: ${f.toPath}")
}
}
private val sbtConfig = scalaConfig

Expand Down Expand Up @@ -320,14 +319,14 @@ object ScalafmtPlugin extends AutoPlugin {
throwOnFailure(checkFilteredSources(filterFiles(sources, dirs)))

private def checkFilteredSources(sources: Seq[File]): ScalafmtAnalysis = {
if (sources.nonEmpty) {
if (sources.nonEmpty)
log.info(s"Checking ${sources.size} Scala sources ($baseDir)...")
}
val unformatted = Set.newBuilder[File]
withFormattedSources(Unit, sources) { (_, file, input, output) =>
val diff = if (errorHandling.printDiff) {
DiffUtils.unifiedDiff("/" + asRelative(file), input, output)
} else ""
val diff =
if (errorHandling.printDiff)
DiffUtils.unifiedDiff("/" + asRelative(file), input, output)
else ""
val suffix = if (diff.isEmpty) "" else '\n' + diff
log.warn(s"$file isn't formatted properly!$suffix")
unformatted += file
Expand Down Expand Up @@ -404,9 +403,8 @@ object ScalafmtPlugin extends AutoPlugin {
pathname.getAbsolutePath.startsWith(targetDirectory)
)
.get
} else {
} else
Nil
}
}

private def scalafmtTask(
Expand Down Expand Up @@ -500,11 +498,10 @@ object ScalafmtPlugin extends AutoPlugin {
scalafmtCheck := getScalafmtSourcesTask(scalafmtCheckTask).value,
scalafmtSbtCheck := getScalafmtSbtTasks(scalafmtSbtCheckTask).value,
scalafmtDoFormatOnCompile := Def.settingDyn {
if (scalafmtOnCompile.value) {
if (scalafmtOnCompile.value)
scalafmt in resolvedScoped.value.scope
} else {
else
Def.task(())
}
}.value,
sources in Compile := (sources in Compile)
.dependsOn(scalafmtDoFormatOnCompile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ class ScalafmtSbtReporter(
res.write(" [")
res.write(file.toString)
res.write(']')
if (null != e && !toThrow) {
if (null != e && !toThrow)
if (errorHandling.detailedErrorEnabled)
e.printStackTrace(new PrintWriter(res))
else if (messageOpt ne nestedMessage) nestedMessage.foreach { x =>
res.write(": ")
res.write(x)
}
}
res.toString
}

Expand Down

0 comments on commit 539d461

Please # to comment.