From c4cd2a0df2c6ee67395699114c2b4327e89485c7 Mon Sep 17 00:00:00 2001 From: Anbarasan Thangapalam Date: Sat, 21 Jul 2018 03:57:03 +0800 Subject: [PATCH 1/4] Add and configure sbt-wartremover --- build.sbt | 3 +++ project/plugins.sbt | 1 + .../scalaz-sbt/wartremover/project/build.properties | 1 + src/sbt-test/scalaz-sbt/wartremover/project/test.sbt | 6 ++++++ .../scalaz-sbt/wartremover/src/main/scala/Test.scala | 3 +++ src/sbt-test/scalaz-sbt/wartremover/test | 4 ++++ src/sbt-test/scalaz-sbt/wartremover/test.sbt | 3 +++ 7 files changed, 21 insertions(+) create mode 100644 src/sbt-test/scalaz-sbt/wartremover/project/build.properties create mode 100644 src/sbt-test/scalaz-sbt/wartremover/project/test.sbt create mode 100644 src/sbt-test/scalaz-sbt/wartremover/src/main/scala/Test.scala create mode 100644 src/sbt-test/scalaz-sbt/wartremover/test create mode 100644 src/sbt-test/scalaz-sbt/wartremover/test.sbt diff --git a/build.sbt b/build.sbt index 7c0778b..14c7476 100644 --- a/build.sbt +++ b/build.sbt @@ -18,3 +18,6 @@ addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3") scalafmtOnCompile := true + +// Wart remover settings +wartremoverWarnings in (Compile, compile) ++= Warts.unsafe \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index e249b2e..1dbe7db 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,3 @@ libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") +addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1") \ No newline at end of file diff --git a/src/sbt-test/scalaz-sbt/wartremover/project/build.properties b/src/sbt-test/scalaz-sbt/wartremover/project/build.properties new file mode 100644 index 0000000..bf24547 --- /dev/null +++ b/src/sbt-test/scalaz-sbt/wartremover/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.1.6 \ No newline at end of file diff --git a/src/sbt-test/scalaz-sbt/wartremover/project/test.sbt b/src/sbt-test/scalaz-sbt/wartremover/project/test.sbt new file mode 100644 index 0000000..d0af073 --- /dev/null +++ b/src/sbt-test/scalaz-sbt/wartremover/project/test.sbt @@ -0,0 +1,6 @@ +val pluginVersion = + sys.props + .get("plugin.version") + .getOrElse(sys.error("Sys prop plugin.version must be defined!")) + +addSbtPlugin("org.scalaz" % "scalaz-sbt" % pluginVersion) diff --git a/src/sbt-test/scalaz-sbt/wartremover/src/main/scala/Test.scala b/src/sbt-test/scalaz-sbt/wartremover/src/main/scala/Test.scala new file mode 100644 index 0000000..1352e81 --- /dev/null +++ b/src/sbt-test/scalaz-sbt/wartremover/src/main/scala/Test.scala @@ -0,0 +1,3 @@ +object Test { + def foo(a: String, b: Int): String = b + a +} diff --git a/src/sbt-test/scalaz-sbt/wartremover/test b/src/sbt-test/scalaz-sbt/wartremover/test new file mode 100644 index 0000000..097381b --- /dev/null +++ b/src/sbt-test/scalaz-sbt/wartremover/test @@ -0,0 +1,4 @@ +# Verify that the sbt-wartremover plugin is correctly activated + +> clean +> compile diff --git a/src/sbt-test/scalaz-sbt/wartremover/test.sbt b/src/sbt-test/scalaz-sbt/wartremover/test.sbt new file mode 100644 index 0000000..bfdd9a3 --- /dev/null +++ b/src/sbt-test/scalaz-sbt/wartremover/test.sbt @@ -0,0 +1,3 @@ +enablePlugins(ScalazPlugin) + +name := "wartremover" \ No newline at end of file From e9c20f7976aa2091a5ec4c220940e5fc16ec9ad3 Mon Sep 17 00:00:00 2001 From: Anbarasan Thangapalam Date: Sat, 21 Jul 2018 04:33:02 +0800 Subject: [PATCH 2/4] removed unnecessary comments --- build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sbt b/build.sbt index 14c7476..29e9d21 100644 --- a/build.sbt +++ b/build.sbt @@ -19,5 +19,4 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3") scalafmtOnCompile := true -// Wart remover settings wartremoverWarnings in (Compile, compile) ++= Warts.unsafe \ No newline at end of file From 1af0013083f087e09c09050e5490a098372e3e1f Mon Sep 17 00:00:00 2001 From: Anbarasan Thangapalam Date: Tue, 24 Jul 2018 00:52:16 +0800 Subject: [PATCH 3/4] add wart settings to projects using the plugin via the projectSettings method of ScalazPlugin --- build.sbt | 5 ++--- src/main/scala/Compilation.scala | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/build.sbt b/build.sbt index 29e9d21..aa09e23 100644 --- a/build.sbt +++ b/build.sbt @@ -16,7 +16,6 @@ addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.1.1") addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3") +addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1") -scalafmtOnCompile := true - -wartremoverWarnings in (Compile, compile) ++= Warts.unsafe \ No newline at end of file +scalafmtOnCompile := true \ No newline at end of file diff --git a/src/main/scala/Compilation.scala b/src/main/scala/Compilation.scala index dced34a..58468b5 100644 --- a/src/main/scala/Compilation.scala +++ b/src/main/scala/Compilation.scala @@ -1,7 +1,10 @@ package scalaz.build -import sbt._, Keys._ import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile +import sbt.Keys._ +import sbt._ +import wartremover.WartRemover.autoImport._ +import wartremover.{Wart, Warts} object Compilation { @@ -23,9 +26,9 @@ object Compilation { ), libraryDependencies ++= compilerPlugins ++ Seq( "com.github.ghik" %% "silencer-lib" % silencerVersion % Provided, - "org.scalacheck" %% "scalacheck" % "1.14.0" % Test + "org.scalacheck" %% "scalacheck" % "1.14.0" % Test ) - ) + ) ++ wartSettings val silencerVersion = "1.0" @@ -72,6 +75,10 @@ object Compilation { "-Ywarn-value-discard" // Warn when non-Unit expression results are unused. ) + lazy val wartSettings: Seq[Def.Setting[Seq[Wart]]] = Seq( + wartremoverWarnings in Compile ++= Warts.unsafe + ) + def crossScalacOptions(version: String): Seq[String] = CrossVersion.partialVersion(version) match { case Some((2L, 12L)) => @@ -93,8 +100,8 @@ object Compilation { } val compilerPlugins = Seq( - compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7"), - compilerPlugin("com.github.tomasmikula" %% "pascal" % "0.2.1"), - compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion) + compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7"), + compilerPlugin("com.github.tomasmikula" %% "pascal" % "0.2.1"), + compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion) ) } From 509d710fab80a93fdcf7dff8db69edf219b80455 Mon Sep 17 00:00:00 2001 From: Anbarasan Thangapalam Date: Thu, 26 Jul 2018 01:30:30 +0800 Subject: [PATCH 4/4] extracted out the wartRemoverSettings as object and by default all the warts are turned off. We can override the wart remover settings in project --- project/plugins.sbt | 2 +- src/main/scala/Compilation.scala | 19 ++++++------------- src/main/scala/ScalazPlugin.scala | 5 +++-- src/main/scala/WartRemoverSettings.scala | 12 ++++++++++++ src/sbt-test/scalaz-sbt/wartremover/test | 2 +- src/sbt-test/scalaz-sbt/wartremover/test.sbt | 9 ++++++--- 6 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/main/scala/WartRemoverSettings.scala diff --git a/project/plugins.sbt b/project/plugins.sbt index 1dbe7db..be9935d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC3") -addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1") \ No newline at end of file +addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1") \ No newline at end of file diff --git a/src/main/scala/Compilation.scala b/src/main/scala/Compilation.scala index 58468b5..dced34a 100644 --- a/src/main/scala/Compilation.scala +++ b/src/main/scala/Compilation.scala @@ -1,10 +1,7 @@ package scalaz.build +import sbt._, Keys._ import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile -import sbt.Keys._ -import sbt._ -import wartremover.WartRemover.autoImport._ -import wartremover.{Wart, Warts} object Compilation { @@ -26,9 +23,9 @@ object Compilation { ), libraryDependencies ++= compilerPlugins ++ Seq( "com.github.ghik" %% "silencer-lib" % silencerVersion % Provided, - "org.scalacheck" %% "scalacheck" % "1.14.0" % Test + "org.scalacheck" %% "scalacheck" % "1.14.0" % Test ) - ) ++ wartSettings + ) val silencerVersion = "1.0" @@ -75,10 +72,6 @@ object Compilation { "-Ywarn-value-discard" // Warn when non-Unit expression results are unused. ) - lazy val wartSettings: Seq[Def.Setting[Seq[Wart]]] = Seq( - wartremoverWarnings in Compile ++= Warts.unsafe - ) - def crossScalacOptions(version: String): Seq[String] = CrossVersion.partialVersion(version) match { case Some((2L, 12L)) => @@ -100,8 +93,8 @@ object Compilation { } val compilerPlugins = Seq( - compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7"), - compilerPlugin("com.github.tomasmikula" %% "pascal" % "0.2.1"), - compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion) + compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7"), + compilerPlugin("com.github.tomasmikula" %% "pascal" % "0.2.1"), + compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion) ) } diff --git a/src/main/scala/ScalazPlugin.scala b/src/main/scala/ScalazPlugin.scala index b5c5168..19956e9 100644 --- a/src/main/scala/ScalazPlugin.scala +++ b/src/main/scala/ScalazPlugin.scala @@ -4,12 +4,13 @@ import sbt._ import Keys._ import de.heikoseeberger.sbtheader.HeaderPlugin import org.scalafmt.sbt.ScalafmtPlugin +import wartremover.WartRemover object ScalazPlugin extends AutoPlugin { override def trigger = allRequirements - override def requires = HeaderPlugin && ScalafmtPlugin + override def requires = HeaderPlugin && ScalafmtPlugin && WartRemover override def buildSettings = Compilation.buildSettings ++ @@ -23,5 +24,5 @@ object ScalazPlugin extends AutoPlugin { ) override def projectSettings = - Compilation.projectSettings + Compilation.projectSettings ++ WartRemoverSettings.buildSettings } diff --git a/src/main/scala/WartRemoverSettings.scala b/src/main/scala/WartRemoverSettings.scala new file mode 100644 index 0000000..07c4e05 --- /dev/null +++ b/src/main/scala/WartRemoverSettings.scala @@ -0,0 +1,12 @@ +package scalaz.build +import sbt.Keys._ +import sbt._ +import wartremover.WartRemover.autoImport.wartremoverErrors +import wartremover.Wart + +object WartRemoverSettings { + + val buildSettings = Seq( + wartremoverErrors in (Compile, compile) += Wart.Nothing + ) +} diff --git a/src/sbt-test/scalaz-sbt/wartremover/test b/src/sbt-test/scalaz-sbt/wartremover/test index 097381b..765ec12 100644 --- a/src/sbt-test/scalaz-sbt/wartremover/test +++ b/src/sbt-test/scalaz-sbt/wartremover/test @@ -1,4 +1,4 @@ # Verify that the sbt-wartremover plugin is correctly activated > clean -> compile +-> compile diff --git a/src/sbt-test/scalaz-sbt/wartremover/test.sbt b/src/sbt-test/scalaz-sbt/wartremover/test.sbt index bfdd9a3..1a5892b 100644 --- a/src/sbt-test/scalaz-sbt/wartremover/test.sbt +++ b/src/sbt-test/scalaz-sbt/wartremover/test.sbt @@ -1,3 +1,6 @@ -enablePlugins(ScalazPlugin) - -name := "wartremover" \ No newline at end of file +lazy val app = project + .in(file(".")) + .settings( + name := "wartremover", + wartremoverErrors in (Compile, compile) ++= Warts.all + ).enablePlugins(ScalazPlugin)