From 309c19af66f5612e7f1ac9b9663b19e3d112a2ce Mon Sep 17 00:00:00 2001 From: Albert Meltzer Date: Sun, 14 Nov 2021 13:41:48 -0800 Subject: [PATCH] Do not invoke formatting on empty list of files --- .../src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala index faafbca..fc5a02a 100644 --- a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala +++ b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala @@ -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)