From 46d9b4399323ddb3534d4694d1eebd6604baa892 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 2 Jul 2018 19:31:40 -0700 Subject: Improve reporting of fatal warnings --- src/main/scala/xyz.driver.sbt/Linting.scala | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz.driver.sbt/Linting.scala b/src/main/scala/xyz.driver.sbt/Linting.scala index 8a293b6..1c33a6a 100644 --- a/src/main/scala/xyz.driver.sbt/Linting.scala +++ b/src/main/scala/xyz.driver.sbt/Linting.scala @@ -1,7 +1,7 @@ package xyz.driver.sbt -import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport.{scalafmtConfig, _} -import com.lucidchart.sbt.scalafmt.ScalafmtPlugin +import org.scalafmt.sbt.ScalafmtPlugin +import org.scalafmt.sbt.ScalafmtPlugin.autoImport._ import org.scalastyle.sbt.ScalastylePlugin import org.scalastyle.sbt.ScalastylePlugin.autoImport.{scalastyle, scalastyleConfig} import sbt.Keys._ @@ -20,19 +20,25 @@ object Linting extends AutoPlugin { val packaged = getClass.getClassLoader.getResourceAsStream("scalafmt.conf") val out = file(".scalafmt.conf") IO.write(out, IO.readBytes(packaged)) - out + Some(out) }, - scalafmtTestOnCompile in Test := true + test in Test := { + (test in Test).value + scalafmtCheck.value + } ) lazy val scalastyleSettings: Seq[Def.Setting[_]] = Seq( scalastyleConfig := { val stream = getClass.getClassLoader.getResourceAsStream("scalastyle-config.xml") - val out = file(".scalastyle-config.xml") + val out = file("scalastyle-config.xml") IO.write(out, IO.readBytes(stream)) out }, - test in Test := (test in Test).dependsOn((scalastyle in Test).toTask("")).value + test in Test := { + (test in Test).value + (scalastyle in Test).toTask("").value + } ) lazy val scalacSettings: Seq[Def.Setting[_]] = Seq( @@ -62,14 +68,23 @@ object Linting extends AutoPlugin { case (_, info) => info.getReportedProblems } var deprecationsOnly = true - problems.foreach { problem => - if (!problem.message().contains("is deprecated")) { - deprecationsOnly = false - log.error(s"[fatal warning] ${problem.message()}") - } + problems.foreach { + problem => + if (!problem.message().contains("is deprecated")) { + deprecationsOnly = false + val pos = problem.position + val file = pos.sourcePath.asScala.getOrElse("?") + val line = pos.line.asScala.map(_.toString).getOrElse("?") + val col = pos.pointer.asScala.map(_.toString).getOrElse("?") + val msg = problem.message + val desc = pos.lineContent() + "\n" + pos.pointerSpace.asScala + .getOrElse("") + "^" + log.error(s"[fatal warning] $file:$line:$col $msg\n$desc") + } } if (!deprecationsOnly) - throw new FatalWarningsException("Fatal warnings: some warnings other than deprecations were found.") + throw new MessageOnlyException("Fatal warnings: some warnings other than deprecations were found. Disable " + + "the `Linting` plugin to ignore fatal warnings.") compiled } ) @@ -79,4 +94,3 @@ object Linting extends AutoPlugin { override def projectSettings: Seq[Def.Setting[_]] = inConfig(Compile)(lintSettings) ++ inConfig(Test)(lintSettings) } -case class FatalWarningsException(message: String) extends Exception(message) -- cgit v1.2.3