diff options
author | Jakob Odersky <jakob@driver.xyz> | 2018-07-02 19:31:40 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@driver.xyz> | 2018-07-02 19:31:40 -0700 |
commit | 46d9b4399323ddb3534d4694d1eebd6604baa892 (patch) | |
tree | 342ee6b1643d50af4d2c08d44050a3ca23086e91 /src | |
parent | 22e03476cad9a7ce34415bba150771e974a85ef5 (diff) | |
download | sbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.tar.gz sbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.tar.bz2 sbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.zip |
Improve reporting of fatal warnings
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/xyz.driver.sbt/Linting.scala | 40 |
1 files changed, 27 insertions, 13 deletions
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) |