Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for re-introduced warnings in scala 3.3.0 #147

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ and Scala 3.x releases:

* 3.0.2
* 3.1.3
* 3.3.0

### Conduct

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import scala.Ordering.Implicits._
case class ScalaVersion(major: Long, minor: Long, patch: Long) {
def isBetween(addedVersion: ScalaVersion, removedVersion: ScalaVersion) =
this >= addedVersion && this < removedVersion

def isAfter(addedVersion: ScalaVersion) = this >= addedVersion
DavidGregory084 marked this conversation as resolved.
Show resolved Hide resolved
}

object ScalaVersion {
Expand All @@ -38,6 +40,7 @@ object ScalaVersion {
val V2_13_9 = ScalaVersion(2, 13, 9)
val V3_0_0 = ScalaVersion(3, 0, 0)
val V3_1_0 = ScalaVersion(3, 1, 0)
val V3_3_0 = ScalaVersion(3, 3, 0)

implicit val scalaVersionOrdering: Ordering[ScalaVersion] =
Ordering.by(version => (version.major, version.minor, version.patch))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private[davidgregory084] trait ScalacOptions {
/** Warn when non-Unit expression results are unused.
*/
val warnValueDiscard =
warnOption("value-discard", version => version.isBetween(V2_13_0, V3_0_0))
warnOption("value-discard", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn when an expression is ignored because it is followed by another expression.
*/
Expand All @@ -589,29 +589,29 @@ private[davidgregory084] trait ScalacOptions {
/** Warn if an implicit parameter is unused.
*/
val warnUnusedImplicits =
warnUnusedOption("implicits", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("implicits", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn if an explicit parameter is unused.
*/
val warnUnusedExplicits =
warnUnusedOption("explicits", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("explicits", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn if an import selector is not referenced.
*/
val warnUnusedImports =
warnUnusedOption("imports", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("imports", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn if a local definition is unused.
*/
val warnUnusedLocals =
warnUnusedOption("locals", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("locals", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn if either explicit or implicit parameters are unused.
*
* Equivalent to -Wunused:explicits,implicits.
*/
val warnUnusedParams =
warnUnusedOption("params", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("params", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Warn if a variable bound in a pattern is unused.
*/
Expand All @@ -621,7 +621,7 @@ private[davidgregory084] trait ScalacOptions {
/** Warn if a private member is unused.
*/
val warnUnusedPrivates =
warnUnusedOption("privates", version => version.isBetween(V2_13_0, V3_0_0))
warnUnusedOption("privates", version => version.isBetween(V2_13_0, V3_0_0) || version.isAfter(V3_3_0))

/** Unused warning options (-Wunused:)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ val Scala212 = "2.12.17"
val Scala213 = "2.13.8"
val Scala30 = "3.0.2"
val Scala31 = "3.1.3"
val Scala33 = "3.3.0"

crossScalaVersions := Seq(
Scala211,
Scala212,
Scala213,
Scala30,
Scala31
Scala31,
Scala33,
)

Compile / tpolecatOptionsMode := CiMode
Expand Down
28 changes: 27 additions & 1 deletion plugin/src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ val Scala212 = "2.12.17"
val Scala213 = "2.13.8"
val Scala30 = "3.0.2"
val Scala31 = "3.1.3"
val Scala33 = "3.3.0"

enablePlugins(OtherPlugin)

Expand All @@ -15,7 +16,8 @@ crossScalaVersions := Seq(
Scala212,
Scala213,
Scala30,
Scala31
Scala31,
Scala33
)

tpolecatDevModeOptions ++= Set(
Expand Down Expand Up @@ -185,6 +187,27 @@ val Scala31Options =
"-source",
"3.0-migration"
)
val Scala33Options =
Seq(
"-encoding",
"utf8",
"-deprecation",
"-feature",
"-unchecked",
"-language:experimental.macros",
"-language:higherKinds",
"-language:implicitConversions",
"-Ykind-projector",
"-Wvalue-discard",
"-Wunused:implicits",
"-Wunused:explicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates",
"-source",
"3.0-migration",
Comment on lines +208 to +209
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sbt-typelevel was making this mistake as well. It seems this is not the sort of thing a plugin should be doing. But that will have to be fixed in another PR / breaking release.

Without the project author explicitly opting into it. I think -source is dangerous and should not be enabled without thinking through all the consequences (and ideally it should only be used temporarily during a migration)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry - this isn't actually enabled by default, it's just enabled in the test suite to make sure that users can manipulate options for each mode separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

TaskKey[Unit]("checkDevMode") := {
val scalaV = scalaVersion.value
Expand All @@ -195,6 +218,7 @@ TaskKey[Unit]("checkDevMode") := {
case Scala213 => Scala213Options
case Scala30 => Scala30Options
case Scala31 => Scala31Options
case Scala33 => Scala33Options
}

val actualOptions = scalacOptions.value
Expand All @@ -211,6 +235,7 @@ TaskKey[Unit]("checkCiMode") := {
case Scala213 => Scala213Options ++ Seq("-Xfatal-warnings")
case Scala30 => Scala30Options ++ Seq("-Xfatal-warnings")
case Scala31 => Scala31Options ++ Seq("-Xfatal-warnings")
case Scala33 => Scala33Options ++ Seq("-Xfatal-warnings")
}

val actualOptions = scalacOptions.value
Expand Down Expand Up @@ -251,6 +276,7 @@ TaskKey[Unit]("checkReleaseMode") := {
)
case Scala30 => Scala30Options ++ fatalWarnings ++ releaseOptions
case Scala31 => Scala31Options ++ fatalWarnings ++ releaseOptions
case Scala33 => Scala33Options ++ fatalWarnings ++ releaseOptions
}

val actualOptions = scalacOptions.value
Expand Down