From 85551920af209e26c2d2d042fb9854fb544086bd Mon Sep 17 00:00:00 2001 From: Ondra Pelech Date: Wed, 2 Sep 2020 12:59:08 +0200 Subject: [PATCH] Add Mima and Rewarn sbt plugins (#43) * Add Mima and Rewarn sbt plugins * trait DecentScala * disable "DisableSyntax.valInAbstract" --- .scalafix.conf | 1 - build.sbt | 33 +++++++- project/Dependencies.scala | 4 + project/plugins.sbt | 6 ++ .../sbtdecentscala/DecentScalaPlugin.scala | 75 +++++++++++-------- 5 files changed, 82 insertions(+), 37 deletions(-) diff --git a/.scalafix.conf b/.scalafix.conf index 7e8ac48..ad32a82 100644 --- a/.scalafix.conf +++ b/.scalafix.conf @@ -46,7 +46,6 @@ DisableSyntax { noTabs = true noThrows = true noUniversalEquality = true - noValInAbstract = true noVars = true noWhileLoops = true noXml = true diff --git a/build.sbt b/build.sbt index d5f9197..15ee8c9 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,9 @@ +import com.typesafe.tools.mima.core._ +import sbt.Defaults.sbtPluginExtra + Global / onChangedBuildSource := ReloadOnSourceChanges ThisBuild / turbo := true -ThisBuild / scalaVersion := "2.12.11" +ThisBuild / scalaVersion := "2.12.12" lazy val sbtDecentScala = project .in(file(".")) @@ -8,7 +11,9 @@ lazy val sbtDecentScala = project .settings( name := "sbt-decent-scala", sbtPlugin := true, + addSbtPlugin(Dependencies.sbtMima), addSbtPlugin(Dependencies.sbtMissinglink), + addSbtPlugin(Dependencies.sbtRewarn), addSbtPlugin(Dependencies.sbtScalafmt), addSbtPlugin(Dependencies.sbtScalafix), addSbtPlugin(Dependencies.sbtTpolecat), @@ -50,7 +55,27 @@ lazy val commonSettings: List[Def.Setting[_]] = List( moduleFilter(organization = "org.apache.logging.log4j", name = "log4j-core"), moduleFilter(organization = "org.apache.logging.log4j", name = "log4j-slf4j-impl"), moduleFilter(organization = "com.squareup.okhttp3", name = "okhttp"), + moduleFilter(organization = "com.timushev.sbt", name = "sbt-rewarn"), + ), + mimaPreviousArtifacts := Set( + sbtPluginExtra( + organization.value % moduleName.value % "0.4.0+8-55b6f77b", + (sbtBinaryVersion in pluginCrossBuild).value, + (scalaBinaryVersion in update).value, + ), + ), + mimaBinaryIssueFilters ++= List( + ProblemFilters.exclude[DirectMissingMethodProblem]( + "com.github.sideeffffect.sbtdecentscala.DecentScalaPlugin.projectSettings", + ), + ProblemFilters.exclude[IncompatibleResultTypeProblem]( + "com.github.sideeffffect.sbtdecentscala.DecentScalaPlugin.projectSettings", + ), ), + ciReleaseCont, +) + +lazy val ciReleaseCont = { commands += Command.command("ci-release-cont") { currentState => if (!CiReleasePlugin.isSecure) { println("No access to secret variables, doing nothing") @@ -87,8 +112,8 @@ lazy val commonSettings: List[Def.Setting[_]] = List( currentState } } - }, -) + } +} addCommandAlias( "ci", @@ -97,7 +122,7 @@ addCommandAlias( addCommandAlias( "check", - "; lint; missinglinkCheck; +test", + "; lint; +missinglinkCheck; +mimaReportBinaryIssues; +test", ) addCommandAlias( diff --git a/project/Dependencies.scala b/project/Dependencies.scala index bb18d8f..a0f1ee9 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -7,7 +7,9 @@ object Dependencies { val betterMonadicFor = "0.3.1" val kindProjector = "0.10.3" val organizeImports = "0.4.0" + val sbtMima = "0.7.0" val sbtMissinglink = "0.3.1" + val sbtRewarn = "0.1.0" val sbtScalafmt = "2.4.2" val sbtScalafix = "0.9.19" val sbtTpolecat = "0.1.13" @@ -19,7 +21,9 @@ object Dependencies { val betterMonadicFor = "com.olegpy" %% "better-monadic-for" % Versions.betterMonadicFor val kindProjector = "org.typelevel" %% "kind-projector" % Versions.kindProjector val organizeImports = "com.github.liancheng" %% "organize-imports" % Versions.organizeImports + val sbtMima = "com.typesafe" % "sbt-mima-plugin" % Versions.sbtMima val sbtMissinglink = "ch.epfl.scala" % "sbt-missinglink" % Versions.sbtMissinglink + val sbtRewarn = "com.timushev.sbt" % "sbt-rewarn" % Versions.sbtRewarn val sbtScalafmt = "org.scalameta" % "sbt-scalafmt" % Versions.sbtScalafmt val sbtScalafix = "ch.epfl.scala" % "sbt-scalafix" % Versions.sbtScalafix val sbtTpolecat = "io.github.davidgregory084" % "sbt-tpolecat" % Versions.sbtTpolecat diff --git a/project/plugins.sbt b/project/plugins.sbt index 0fdc41a..d940184 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,20 +1,26 @@ val Dependencies = new { val Versions = new { val sbtCiRelease = "1.5.3" + val sbtMima = "0.7.0" val sbtMissinglink = "0.3.1" + val sbtRewarn = "0.1.0" val sbtScalafmt = "2.4.2" val sbtScalafix = "0.9.19" val sbtTpolecat = "0.1.13" } val sbtCiRelease = "com.geirsson" % "sbt-ci-release" % Versions.sbtCiRelease + val sbtMima = "com.typesafe" % "sbt-mima-plugin" % Versions.sbtMima val sbtMissinglink = "ch.epfl.scala" % "sbt-missinglink" % Versions.sbtMissinglink + val sbtRewarn = "com.timushev.sbt" % "sbt-rewarn" % Versions.sbtRewarn val sbtScalafmt = "org.scalameta" % "sbt-scalafmt" % Versions.sbtScalafmt val sbtScalafix = "ch.epfl.scala" % "sbt-scalafix" % Versions.sbtScalafix val sbtTpolecat = "io.github.davidgregory084" % "sbt-tpolecat" % Versions.sbtTpolecat } addSbtPlugin(Dependencies.sbtCiRelease) +addSbtPlugin(Dependencies.sbtMima) addSbtPlugin(Dependencies.sbtMissinglink) +addSbtPlugin(Dependencies.sbtRewarn) addSbtPlugin(Dependencies.sbtScalafmt) addSbtPlugin(Dependencies.sbtScalafix) addSbtPlugin(Dependencies.sbtTpolecat) diff --git a/src/main/scala/com/github/sideeffffect/sbtdecentscala/DecentScalaPlugin.scala b/src/main/scala/com/github/sideeffffect/sbtdecentscala/DecentScalaPlugin.scala index 935245f..c8ddef7 100644 --- a/src/main/scala/com/github/sideeffffect/sbtdecentscala/DecentScalaPlugin.scala +++ b/src/main/scala/com/github/sideeffffect/sbtdecentscala/DecentScalaPlugin.scala @@ -1,6 +1,8 @@ package com.github.sideeffffect.sbtdecentscala import ch.epfl.scala.sbtmissinglink.MissingLinkPlugin +import com.timushev.sbt.rewarn.RewarnPlugin +import com.typesafe.tools.mima.plugin.MimaPlugin import io.github.davidgregory084.TpolecatPlugin import org.scalafmt.sbt.ScalafmtPlugin import sbt.Keys._ @@ -10,40 +12,49 @@ import scalafix.sbt.ScalafixPlugin.autoImport._ object DecentScalaPlugin extends AutoPlugin { - override def requires: Plugins = MissingLinkPlugin && ScalafixPlugin && ScalafmtPlugin && TpolecatPlugin + override def requires: Plugins = + MimaPlugin && MissingLinkPlugin && RewarnPlugin && ScalafixPlugin && ScalafmtPlugin && TpolecatPlugin override def trigger: PluginTrigger = allRequirements - override def projectSettings: List[Def.Setting[_]] = - List( - libraryDependencies ++= List( - compilerPlugin(Dependencies.betterMonadicFor), - compilerPlugin(Dependencies.kindProjector), - compilerPlugin(Dependencies.silencer), - Dependencies.silencerLib, - ), - semanticdbEnabled := true, // enable SemanticDB - semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version - ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), - ThisBuild / scalafixDependencies ++= List( - Dependencies.organizeImports, - Dependencies.scaluzzi, - ), - scalacOptions ++= List( - "-P:silencer:checkUnused", - "-Ywarn-macros:after", - ), - scalacOptions --= { - if (!sys.env.contains("CI")) - List("-Xfatal-warnings") // to enable Scalafix - else - List() - }, - ) ++ - addCommandAlias("check", "; lint; missinglinkCheck; +test") ++ - addCommandAlias( - "lint", - "; scalafmtSbtCheck; scalafmtCheckAll; compile:scalafix --check; test:scalafix --check", + object autoImport { + + object DecentScala extends DecentScala + + } + + trait DecentScala { + lazy val decentScalaSettings: List[Def.Setting[_]] = + List( + libraryDependencies ++= List( + compilerPlugin(Dependencies.betterMonadicFor), + compilerPlugin(Dependencies.kindProjector), + compilerPlugin(Dependencies.silencer), + Dependencies.silencerLib, + ), + semanticdbEnabled := true, // enable SemanticDB + semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version + ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), + ThisBuild / scalafixDependencies ++= List( + Dependencies.organizeImports, + Dependencies.scaluzzi, + ), + scalacOptions ++= List( + "-P:silencer:checkUnused", + "-Ywarn-macros:after", + ), + scalacOptions --= { + if (!sys.env.contains("CI")) + List("-Xfatal-warnings") // to enable Scalafix + else + List() + }, ) ++ - addCommandAlias("fix", "; compile:scalafix; test:scalafix; scalafmtSbt; scalafmtAll") + addCommandAlias("check", "; lint; +missinglinkCheck; +mimaReportBinaryIssues; +test") ++ + addCommandAlias( + "lint", + "; scalafmtSbtCheck; scalafmtCheckAll; compile:scalafix --check; test:scalafix --check", + ) ++ + addCommandAlias("fix", "; compile:scalafix; test:scalafix; scalafmtSbt; scalafmtAll") + } }