diff --git a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala index 6563bbf..d47dc6a 100644 --- a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala +++ b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala @@ -138,6 +138,7 @@ object ScalafmtPlugin extends AutoPlugin { private class FormatSession( config: Path, taskStreams: TaskStreams, + cacheStoreFactory: CacheStoreFactory, resolvers: Seq[Resolver], currentProject: ResolvedProject, filterMode: String, @@ -239,10 +240,7 @@ object ScalafmtPlugin extends AutoPlugin { res } - def formatTrackedSources( - cacheStoreFactory: CacheStoreFactory, - sources: Seq[File] - ): Unit = { + def formatTrackedSources(sources: Seq[File]): Unit = { val filteredSources = filterFiles(sources) trackSourcesAndConfig(cacheStoreFactory, filteredSources) { (outDiff, configChanged, prev) => @@ -272,10 +270,7 @@ object ScalafmtPlugin extends AutoPlugin { if (cnt > 0) log.info(s"Reformatted $cnt Scala sources") } - def checkTrackedSources( - cacheStoreFactory: CacheStoreFactory, - sources: Seq[File] - ): ScalafmtAnalysis = { + def checkTrackedSources(sources: Seq[File]): ScalafmtAnalysis = { val filteredSources = filterFiles(sources) trackSourcesAndConfig(cacheStoreFactory, filteredSources) { (outDiff, configChanged, prev) => @@ -393,15 +388,12 @@ object ScalafmtPlugin extends AutoPlugin { private def scalafmtTask(sources: Seq[File], session: FormatSession) = Def.task { - session.formatTrackedSources(streams.value.cacheStoreFactory, sources) + session.formatTrackedSources(sources) } tag (ScalafmtTagPack: _*) private def scalafmtCheckTask(sources: Seq[File], session: FormatSession) = Def.task { - val analysis = session.checkTrackedSources( - (scalafmt / streams).value.cacheStoreFactory, - sources - ) + val analysis = session.checkTrackedSources(sources) throwOnFailure(analysis) } tag (ScalafmtTagPack: _*) @@ -451,6 +443,7 @@ object ScalafmtPlugin extends AutoPlugin { val session = new FormatSession( config, streams.value, + (scalafmt / streams).value.cacheStoreFactory, fullResolvers.value, thisProject.value, scalafmtFilter.value, @@ -496,6 +489,7 @@ object ScalafmtPlugin extends AutoPlugin { new FormatSession( scalaConfig.value, streams.value, + (scalafmt / streams).value.cacheStoreFactory, fullResolvers.value, thisProject.value, "", diff --git a/plugin/src/sbt-test/scalafmt-sbt/sbt/test b/plugin/src/sbt-test/scalafmt-sbt/sbt/test index 7a9b892..7e3c4f4 100644 --- a/plugin/src/sbt-test/scalafmt-sbt/sbt/test +++ b/plugin/src/sbt-test/scalafmt-sbt/sbt/test @@ -142,6 +142,10 @@ $ delete p17/src/main/scala/Test2.scala $ copy-file changes/good.scala p17/src/main/scala/Test2.scala > p17/scalafmtCheck > p17/scalafmt +######## formatting other config should not invalidate the cache +$ copy-file changes/bad.scala p17/src/test/scala/Test3.scala +> p17/test:scalafmt +> p17/scalafmtCheck # set up git $ exec git init -b main p18