2019-10-20 06:41:53 +02:00
|
|
|
import sbt._
|
|
|
|
|
import Keys._
|
|
|
|
|
|
|
|
|
|
object HouseRulesPlugin extends AutoPlugin {
|
2021-03-07 23:41:52 +01:00
|
|
|
override def requires = plugins.JvmPlugin
|
2019-10-20 06:41:53 +02:00
|
|
|
override def trigger = allRequirements
|
|
|
|
|
|
|
|
|
|
override def projectSettings: Seq[Def.Setting[_]] = baseSettings
|
|
|
|
|
|
|
|
|
|
lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
|
|
|
|
|
scalacOptions ++= Seq("-encoding", "utf8"),
|
2024-01-30 07:25:36 +01:00
|
|
|
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
|
2019-10-20 06:41:53 +02:00
|
|
|
scalacOptions += "-language:higherKinds",
|
|
|
|
|
scalacOptions += "-language:implicitConversions",
|
|
|
|
|
scalacOptions ++= "-Xfuture".ifScala213OrMinus.value.toList,
|
2024-01-30 07:25:36 +01:00
|
|
|
scalacOptions ++= "-Xlint".ifScala2.value.toList,
|
2024-03-05 10:41:07 +01:00
|
|
|
scalacOptions ++= "-Xfatal-warnings"
|
|
|
|
|
.ifScala3x(_ => {
|
|
|
|
|
sys.props.get("sbt.build.fatal") match {
|
|
|
|
|
case Some(_) => java.lang.Boolean.getBoolean("sbt.build.fatal")
|
|
|
|
|
case _ => true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.value
|
|
|
|
|
.toList,
|
2019-10-20 06:41:53 +02:00
|
|
|
scalacOptions ++= "-Yinline-warnings".ifScala211OrMinus.value.toList,
|
|
|
|
|
scalacOptions ++= "-Yno-adapted-args".ifScala212OrMinus.value.toList,
|
2024-01-30 07:25:36 +01:00
|
|
|
scalacOptions ++= "-Ywarn-dead-code".ifScala2.value.toList,
|
|
|
|
|
scalacOptions ++= "-Ywarn-numeric-widen".ifScala2.value.toList,
|
|
|
|
|
scalacOptions ++= "-Ywarn-value-discard".ifScala2.value.toList,
|
2024-03-05 13:24:31 +01:00
|
|
|
scalacOptions ++= "-Ywarn-unused-import".ifScala2x(v => 11 <= v && v <= 12).value.toList,
|
2024-03-05 15:21:57 +01:00
|
|
|
scalacOptions ++= {
|
|
|
|
|
scalaPartV.value match {
|
2024-03-27 16:18:16 +01:00
|
|
|
case Some((3, _)) => Seq("-Wunused:imports,implicits") // ,nowarn
|
2024-03-05 15:21:57 +01:00
|
|
|
case Some((2, _)) => Seq("-Ywarn-unused:-privates,-locals,-explicits")
|
|
|
|
|
case _ => Seq.empty
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-03-05 13:24:31 +01:00
|
|
|
scalacOptions ++= "-Xsource:3".ifScala2.value.toList
|
2021-12-06 08:06:26 +01:00
|
|
|
) ++ Seq(Compile, Test).flatMap(c =>
|
|
|
|
|
(c / console / scalacOptions) --= Seq("-Ywarn-unused-import", "-Xlint")
|
2019-10-20 06:41:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private def scalaPartV = Def setting (CrossVersion partialVersion scalaVersion.value)
|
|
|
|
|
|
|
|
|
|
private implicit final class AnyWithIfScala[A](val __x: A) {
|
2024-01-30 07:25:36 +01:00
|
|
|
def ifScala2x(p: Long => Boolean) =
|
2024-03-05 11:16:35 +01:00
|
|
|
Def.setting(scalaPartV.value.collect { case (2, y) if p(y) => __x })
|
2024-01-30 07:25:36 +01:00
|
|
|
def ifScala3x(p: Long => Boolean) =
|
2024-03-05 11:16:35 +01:00
|
|
|
Def.setting(scalaPartV.value.collect { case (3, y) if p(y) => __x })
|
2024-01-30 07:25:36 +01:00
|
|
|
def ifScalaLte(v: Long) = ifScala2x(_ <= v)
|
|
|
|
|
def ifScalaGte(v: Long) = ifScala2x(_ >= v)
|
2019-10-20 06:41:53 +02:00
|
|
|
def ifScala211OrMinus = ifScalaLte(11)
|
|
|
|
|
def ifScala211OrPlus = ifScalaGte(11)
|
|
|
|
|
def ifScala212OrMinus = ifScalaLte(12)
|
|
|
|
|
def ifScala213OrMinus = ifScalaLte(13)
|
2024-01-30 07:25:36 +01:00
|
|
|
def ifScala2 = ifScala2x(_ => true)
|
2021-11-16 02:19:26 +01:00
|
|
|
def ifScala3 = Def.setting(
|
|
|
|
|
if (scalaBinaryVersion.value == "3") Seq(__x)
|
|
|
|
|
else Nil
|
|
|
|
|
)
|
2019-10-20 06:41:53 +02:00
|
|
|
}
|
|
|
|
|
}
|