Skip to content

Commit

Permalink
Add Mima and Rewarn sbt plugins (#43)
Browse files Browse the repository at this point in the history
* Add Mima and Rewarn sbt plugins

* trait DecentScala

* disable "DisableSyntax.valInAbstract"
  • Loading branch information
sideeffffect authored Sep 2, 2020
1 parent 55b6f77 commit 8555192
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 37 deletions.
1 change: 0 additions & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DisableSyntax {
noTabs = true
noThrows = true
noUniversalEquality = true
noValInAbstract = true
noVars = true
noWhileLoops = true
noXml = true
Expand Down
33 changes: 29 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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("."))
.settings(commonSettings)
.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),
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -87,8 +112,8 @@ lazy val commonSettings: List[Def.Setting[_]] = List(
currentState
}
}
},
)
}
}

addCommandAlias(
"ci",
Expand All @@ -97,7 +122,7 @@ addCommandAlias(

addCommandAlias(
"check",
"; lint; missinglinkCheck; +test",
"; lint; +missinglinkCheck; +mimaReportBinaryIssues; +test",
)

addCommandAlias(
Expand Down
4 changes: 4 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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._
Expand All @@ -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")
}
}

0 comments on commit 8555192

Please sign in to comment.