aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz.driver.sbt/Linting.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz.driver.sbt/Linting.scala')
-rw-r--r--src/main/scala/xyz.driver.sbt/Linting.scala40
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)