Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

prepare sbt 2.x cross build #329

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
28 changes: 14 additions & 14 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ object ScalafmtPlugin extends AutoPlugin {
case class ScalafmtAnalysis(failedScalafmtCheck: Set[File])
object ScalafmtAnalysis {
import sjsonnew.:*:
import sjsonnew.IsoLList
import sjsonnew.LList
import sjsonnew.LNil
implicit val analysisIso = LList.iso(
{ a: ScalafmtAnalysis =>
("failedScalafmtCheck", a.failedScalafmtCheck) :*: LNil
},
{ in: Set[File] :*: LNil => ScalafmtAnalysis(in.head) },
)
implicit val analysisIso: IsoLList.Aux[ScalafmtAnalysis, Set[File] :*: LNil] =
LList.iso(
(a: ScalafmtAnalysis) =>
("failedScalafmtCheck", a.failedScalafmtCheck) :*: LNil,
(in: Set[File] :*: LNil) => ScalafmtAnalysis(in.head),
)
}

private val scalafmtDoFormatOnCompile =
Expand Down Expand Up @@ -187,7 +188,7 @@ object ScalafmtPlugin extends AutoPlugin {
Try(getFiles) match {
case Failure(x) =>
log.warn(s"format all files; $gitMessage: ${x.getMessage}")
_: Path => true
(_: Path) => true
case Success(x) =>
log.debug(s"considering ${x.length} files $gitMessage")
FileOps.getFileMatcher(x.map(_.path))
Expand Down Expand Up @@ -280,8 +281,7 @@ object ScalafmtPlugin extends AutoPlugin {
if (configChanged) Set.empty
else prev.failedScalafmtCheck & outDiff.unmodified
if (prevFailed.nonEmpty) {
val files: Seq[String] = prevFailed
.map(asRelative)(collection.breakOut)
val files: Seq[String] = prevFailed.iterator.map(asRelative).toSeq
val prefix =
s"$baseDir: ${files.length} files aren't formatted properly:\n"
log.warn(files.sorted.mkString(prefix, "\n", ""))
Expand All @@ -300,15 +300,15 @@ object ScalafmtPlugin extends AutoPlugin {
if (sources.nonEmpty) log
.info(s"Checking ${sources.size} Scala sources ($baseDir)...")
val unformatted = Set.newBuilder[File]
withFormattedSources(Unit, sources) { (_, file, input, output) =>
withFormattedSources((), sources) { (_, file, input, output) =>
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
Unit
()
}
ScalafmtAnalysis(failedScalafmtCheck = unformatted.result())
}
Expand Down Expand Up @@ -359,7 +359,7 @@ object ScalafmtPlugin extends AutoPlugin {
val rootSbt = BuildPaths.configurationSources(thisBase).filterNot(_.isHidden)
val metabuildSbt =
if (rootBase == thisBase)
(BuildPaths.projectStandard(thisBase) ** GlobFilter("*.sbt")).get
(BuildPaths.projectStandard(thisBase) ** GlobFilter("*.sbt")).get()
else Nil
rootSbt ++ metabuildSbt
}
Expand All @@ -375,7 +375,7 @@ object ScalafmtPlugin extends AutoPlugin {
projectDirectory.descendantsExcept(
"*.scala",
(pathname: File) => pathname.getAbsolutePath.startsWith(targetDirectory),
).get
).get()
} else Nil
}

Expand Down Expand Up @@ -434,7 +434,7 @@ object ScalafmtPlugin extends AutoPlugin {
private def getScalafmtTask(
func: (Seq[File], Seq[File], FormatSession) => InitTask,
)(files: Seq[File], dirs: Seq[File], config: Path) = Def.taskDyn[Unit] {
if (files.isEmpty) Def.task(Unit)
if (files.isEmpty) Def.task(())
else {
val session = new FormatSession(
config,
Expand Down