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

Don't use Boolean in check tasks, they throw #165

Merged
merged 1 commit into from
Nov 15, 2021
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
19 changes: 9 additions & 10 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object ScalafmtPlugin extends AutoPlugin {
"Format Scala sources to be compiled incrementally with scalafmt (alias to scalafmt)."
)
val scalafmtCheck =
taskKey[Boolean](
taskKey[Unit](
"Fails if a Scala source is mis-formatted. Does not write to files."
)
val scalafmtOnCompile =
Expand All @@ -48,7 +48,7 @@ object ScalafmtPlugin extends AutoPlugin {
"Format *.sbt and project/*.scala files for this sbt build."
)
val scalafmtSbtCheck =
taskKey[Boolean](
taskKey[Unit](
"Fails if a *.sbt or project/*.scala source is mis-formatted. " +
"Does not write to files."
)
Expand Down Expand Up @@ -246,14 +246,13 @@ object ScalafmtPlugin extends AutoPlugin {
)
}

private def trueOrBoom(analysis: ScalafmtAnalysis): Boolean = {
private def trueOrBoom(analysis: ScalafmtAnalysis): Unit = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private def trueOrBoom(analysis: ScalafmtAnalysis): Unit = {
private def throwOnFailures(analysis: ScalafmtAnalysis): Unit = {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in #168. merging this one for now.

val failureCount = analysis.failedScalafmtCheck.size
if (failureCount > 0) {
throw new MessageOnlyException(
s"${failureCount} files must be formatted"
)
}
true
}

private def warnBadFormat(file: File, log: Logger): Unit =
Expand Down Expand Up @@ -423,17 +422,17 @@ object ScalafmtPlugin extends AutoPlugin {
)
} tag (ScalafmtTagPack: _*)

private def getScalafmtSourcesTask[A](
f: Seq[File] => Def.Initialize[Task[A]]
)(default: A) = Def.taskDyn[A] {
(unmanagedSources in scalafmt).?.value.map(f).getOrElse(Def.task(default))
private def getScalafmtSourcesTask(
f: Seq[File] => Def.Initialize[Task[Unit]]
) = Def.taskDyn[Unit] {
(unmanagedSources in scalafmt).?.value.map(f).getOrElse(Def.task(Unit))
}

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