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 --- build.sbt | 2 +- project/build.properties | 2 +- project/plugins.sbt | 2 +- src/main/scala/xyz.driver.sbt/Linting.scala | 40 +++++++++++++++++++---------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/build.sbt b/build.sbt index b89775c..455387b 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ name := "sbt-settings" scalaVersion := "2.12.6" // Plugins that will be included transitively in projects depending on sbt-settings -addSbtPlugin("com.lucidchart" %% "sbt-scalafmt" % "1.15") +addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") addSbtPlugin("io.spray" %% "sbt-revolver" % "0.9.1") addSbtPlugin("com.eed3si9n" %% "sbt-buildinfo" % "0.9.0") diff --git a/project/build.properties b/project/build.properties index 64cf32f..d6e3507 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.1.4 +sbt.version=1.1.6 diff --git a/project/plugins.sbt b/project/plugins.sbt index a769906..b02946e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,2 @@ -addSbtPlugin("com.lucidchart" %% "sbt-scalafmt" % "1.14") +addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } 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