Skip to content

Commit

Permalink
Do not invoke formatting on empty list of files
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Meltzer authored and kitbellew committed Nov 15, 2021
1 parent 42b9ee2 commit 309c19a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,15 @@ object ScalafmtPlugin extends AutoPlugin {
private def getScalafmtSourcesTask(
f: Seq[File] => Def.Initialize[Task[Unit]]
) = Def.taskDyn[Unit] {
(unmanagedSources in scalafmt).?.value.map(f).getOrElse(Def.task(Unit))
val sources = (unmanagedSources in scalafmt).?.value
sources.filter(_.nonEmpty).map(f).getOrElse(Def.task(Unit))
}

private def getScalafmtSbtTasks(
f: (Seq[File], Path) => Def.Initialize[Task[Unit]]
func: (Seq[File], Path) => Def.Initialize[Task[Unit]]
) = Def.taskDyn[Unit] {
def f(files: Seq[File], config: Path) =
if (files.isEmpty) Def.task[Unit]() else func(files, config)
Def.sequential(
f(sbtSources.value, sbtConfig.value),
f(metabuildSources.value, scalaConfig.value)
Expand Down

0 comments on commit 309c19a

Please sign in to comment.