diff --git a/src/main/scala/io/github/davidgregory084/ScalacOptions.scala b/src/main/scala/io/github/davidgregory084/ScalacOptions.scala index 772e204..118021f 100644 --- a/src/main/scala/io/github/davidgregory084/ScalacOptions.scala +++ b/src/main/scala/io/github/davidgregory084/ScalacOptions.scala @@ -630,4 +630,12 @@ trait ScalacOptions { optimizerInline, optimizerInlineFrom(inlineFromPackages: _*) ) + + /** Default options to exclude in console tasks + */ + val defaultConsoleExclude: Set[ScalacOption] = privateWarnUnusedOptions ++ + warnUnusedOptions ++ + fatalWarningOptions + + privateWarnDeadCode + + warnDeadCode } diff --git a/src/main/scala/io/github/davidgregory084/TpolecatPlugin.scala b/src/main/scala/io/github/davidgregory084/TpolecatPlugin.scala index dd4b3dc..e7c31af 100644 --- a/src/main/scala/io/github/davidgregory084/TpolecatPlugin.scala +++ b/src/main/scala/io/github/davidgregory084/TpolecatPlugin.scala @@ -34,7 +34,7 @@ object TpolecatPlugin extends AutoPlugin { modeScalacOptions: Set[ScalacOption] ): Seq[String] = { val supportedOptions = (CrossVersion.partialVersion(version), version.split('.')) match { - case (Some((0, min)), _) => // dotty prereleases use 0 as major version + case (Some((0, _)), _) => // dotty prereleases use 0 as major version modeScalacOptions .filter(_.isSupported(V3_0_0)) // treat dotty prereleases as 3.0.0 case (Some((maj, min)), Array(maj2, min2, patch)) @@ -51,16 +51,6 @@ object TpolecatPlugin extends AutoPlugin { supportedOptions.toList.flatMap(_.tokens) } - val tpolecatConsoleOptionsFilter = { options: Set[ScalacOption] => - options.filterNot( - ScalacOptions.privateWarnUnusedOptions ++ - ScalacOptions.warnUnusedOptions ++ - ScalacOptions.fatalWarningOptions + - ScalacOptions.privateWarnDeadCode + - ScalacOptions.warnDeadCode - ) - } - val tpolecatDefaultOptionsMode = settingKey[OptionsMode]( "The default mode to use for configuring scalac options via the sbt-tpolecat plugin." ) @@ -96,6 +86,10 @@ object TpolecatPlugin extends AutoPlugin { val tpolecatScalacOptions = settingKey[Set[ScalacOption]]( "The set of scalac options that will be applied by the sbt-tpolecat plugin." ) + + val tpolecatExcludeOptions = settingKey[Set[ScalacOption]]( + "The set of scalac options that will be excluded." + ) } import autoImport._ @@ -129,7 +123,13 @@ object TpolecatPlugin extends AutoPlugin { override def projectSettings: Seq[Setting[_]] = Seq( Def.derive( - scalacOptions ++= scalacOptionsFor(scalaVersion.value, tpolecatScalacOptions.value) + scalacOptions := { + val previous = scalacOptions.value + val scalaV = scalaVersion.value + val filters = scalacOptionsFor(scalaV, tpolecatExcludeOptions.value).toSet + val newOptions = scalacOptionsFor(scalaV, tpolecatScalacOptions.value) + (previous ++ newOptions).filterNot(filters).distinct + } ), tpolecatDevModeOptions := ScalacOptions.default, Def.derive( @@ -145,7 +145,11 @@ object TpolecatPlugin extends AutoPlugin { case ReleaseMode => tpolecatReleaseModeOptions.value } }), - Compile / console / tpolecatScalacOptions ~= tpolecatConsoleOptionsFilter, - Test / console / tpolecatScalacOptions ~= tpolecatConsoleOptionsFilter + Compile / console / tpolecatExcludeOptions ++= ScalacOptions.defaultConsoleExclude, + Test / console / tpolecatExcludeOptions ++= ScalacOptions.defaultConsoleExclude + ) + + override def globalSettings: Seq[Def.Setting[_]] = Seq( + tpolecatExcludeOptions := Set.empty ) } diff --git a/src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt b/src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt index 9d05c05..fb38efe 100644 --- a/src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt +++ b/src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt @@ -244,3 +244,37 @@ TaskKey[Unit]("checkReleaseMode") := { assertEquals(actualOptions, expectedOptions) } + +TaskKey[Unit]("checkConsoleScalacOptions") := { + val shouldBeMissing = ScalacOptions.defaultConsoleExclude.flatMap(_.tokens).toSet + val testConsoleOptions = (Test / console / scalacOptions).value + val compileConsoleOptions = (Compile / console / scalacOptions).value + + testConsoleOptions.foreach { opt => + assert(!shouldBeMissing.contains(opt), s"$opt is not excluded from Test/console") + } + + compileConsoleOptions.foreach { opt => + assert(!shouldBeMissing.contains(opt), s"$opt is not excluded from Compile/console") + } +} + +addCommandAlias( + "addScalacOptionsToThisProject", + "set ThisProject / scalacOptions += \"non-existent-key\"" +) + +TaskKey[Unit]("checkThisProjectScalacOptions") := { + val options = (Compile / scalacOptions).value + assert(options.contains("non-existent-key"), "Scope ThisProject was ignored") +} + +addCommandAlias( + "addScalacOptionsToThisBuild", + "set ThisBuild / scalacOptions += \"non-existent-key-2\"" +) + +TaskKey[Unit]("checkThisBuildScalacOptions") := { + val options = (Compile / scalacOptions).value + assert(options.contains("non-existent-key-2"), "Scope ThisBuild was ignored") +} diff --git a/src/sbt-test/sbt-tpolecat/scalacOptions/test b/src/sbt-test/sbt-tpolecat/scalacOptions/test index 382df71..90a8e71 100644 --- a/src/sbt-test/sbt-tpolecat/scalacOptions/test +++ b/src/sbt-test/sbt-tpolecat/scalacOptions/test @@ -13,3 +13,11 @@ > tpolecatReleaseMode > +checkReleaseMode > +compile +# Check console options +> +checkConsoleScalacOptions +# Check ThisProject +> addScalacOptionsToThisProject +> +checkThisProjectScalacOptions +# Check ThisBuild (Ignored) +> addScalacOptionsToThisBuild +> +checkThisBuildScalacOptions