Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

scalafmt: expand RedundantBraces #309

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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