aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-07-02 19:31:40 -0700
committerJakob Odersky <jakob@driver.xyz>2018-07-02 19:31:40 -0700
commit46d9b4399323ddb3534d4694d1eebd6604baa892 (patch)
tree342ee6b1643d50af4d2c08d44050a3ca23086e91
parent22e03476cad9a7ce34415bba150771e974a85ef5 (diff)
downloadsbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.tar.gz
sbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.tar.bz2
sbt-settings-46d9b4399323ddb3534d4694d1eebd6604baa892.zip
Improve reporting of fatal warnings
-rw-r--r--build.sbt2
-rw-r--r--project/build.properties2
-rw-r--r--project/plugins.sbt2
-rw-r--r--src/main/scala/xyz.driver.sbt/Linting.scala40
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)