Skip to content

Commit

Permalink
Use Def.sequential for formatting sbt sources
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 b7dd5af commit 42b9ee2
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,11 @@ object ScalafmtPlugin extends AutoPlugin {
)
} tag (ScalafmtTagPack: _*)

private def scalafmtSbtTask =
private def scalafmtSbtTask(sources: Seq[File], config: Path) =
Def.task {
formatSources(
sbtSources.value.toSet,
sbtConfig.value,
streams.value.log,
outputStreamWriter(streams.value),
fullResolvers.value,
scalafmtDetailedError.value
)
formatSources(
metabuildSources.value.toSet,
scalaConfig.value,
sources.toSet,
config,
streams.value.log,
outputStreamWriter(streams.value),
fullResolvers.value,
Expand All @@ -398,28 +390,17 @@ object ScalafmtPlugin extends AutoPlugin {
throwOnFailure(analysis)
} tag (ScalafmtTagPack: _*)

private def scalafmtSbtCheckTask =
private def scalafmtSbtCheckTask(sources: Seq[File], config: Path) =
Def.task {
throwOnFailure(
checkSources(
sbtSources.value,
sbtConfig.value,
streams.value.log,
outputStreamWriter(streams.value),
fullResolvers.value,
scalafmtDetailedError.value
)
)
throwOnFailure(
checkSources(
metabuildSources.value,
scalaConfig.value,
streams.value.log,
outputStreamWriter(streams.value),
fullResolvers.value,
scalafmtDetailedError.value
)
val analysis = checkSources(
sources,
config,
streams.value.log,
outputStreamWriter(streams.value),
fullResolvers.value,
scalafmtDetailedError.value
)
throwOnFailure(analysis)
} tag (ScalafmtTagPack: _*)

private def getScalafmtSourcesTask(
Expand All @@ -428,12 +409,21 @@ object ScalafmtPlugin extends AutoPlugin {
(unmanagedSources in scalafmt).?.value.map(f).getOrElse(Def.task(Unit))
}

private def getScalafmtSbtTasks(
f: (Seq[File], Path) => Def.Initialize[Task[Unit]]
) = Def.taskDyn[Unit] {
Def.sequential(
f(sbtSources.value, sbtConfig.value),
f(metabuildSources.value, scalaConfig.value)
)
}

lazy val scalafmtConfigSettings: Seq[Def.Setting[_]] = Seq(
scalafmt := getScalafmtSourcesTask(scalafmtTask).value,
scalafmtIncremental := scalafmt.value,
scalafmtSbt := scalafmtSbtTask.value,
scalafmtSbt := getScalafmtSbtTasks(scalafmtSbtTask).value,
scalafmtCheck := getScalafmtSourcesTask(scalafmtCheckTask).value,
scalafmtSbtCheck := scalafmtSbtCheckTask.value,
scalafmtSbtCheck := getScalafmtSbtTasks(scalafmtSbtCheckTask).value,
scalafmtDoFormatOnCompile := Def.settingDyn {
if (scalafmtOnCompile.value) {
(scalafmt in resolvedScoped.value.scope)
Expand Down

0 comments on commit 42b9ee2

Please sign in to comment.