Skip to content

Commit 28c8c76

Browse files
Merge pull request #60 from typelevel/synchronise-sbt-tpolecat
Synchronise changes from sbt-tpolecat
2 parents cae9f37 + 55c40d9 commit 28c8c76

File tree

2 files changed

+103
-10
lines changed

2 files changed

+103
-10
lines changed

lib/src/main/scala/org/typelevel/scalacoptions/ScalaVersion.scala

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import scala.Ordering.Implicits._
2121
case class ScalaVersion(major: Long, minor: Long, patch: Long) {
2222
def isBetween(addedVersion: ScalaVersion, removedVersion: ScalaVersion) =
2323
this >= addedVersion && this < removedVersion
24+
25+
def isAtLeast(addedVersion: ScalaVersion) = this >= addedVersion
2426
}
2527

2628
object ScalaVersion {
@@ -36,8 +38,10 @@ object ScalaVersion {
3638
val V2_13_4 = ScalaVersion(2, 13, 4)
3739
val V2_13_5 = ScalaVersion(2, 13, 5)
3840
val V2_13_6 = ScalaVersion(2, 13, 6)
41+
val V2_13_9 = ScalaVersion(2, 13, 9)
3942
val V3_0_0 = ScalaVersion(3, 0, 0)
4043
val V3_1_0 = ScalaVersion(3, 1, 0)
44+
val V3_3_0 = ScalaVersion(3, 3, 0)
4145

4246
implicit val scalaVersionOrdering: Ordering[ScalaVersion] =
4347
Ordering.by(version => (version.major, version.minor, version.patch))

lib/src/main/scala/org/typelevel/scalacoptions/ScalacOptions.scala

+99-10
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ private[scalacoptions] trait ScalacOptions {
4747
ScalacOption("-encoding", List(enc), _ => true)
4848

4949
/** Emit warning and location for usages of deprecated APIs.
50+
*
51+
* Deprecated in 2.13.0 and replaced by -Xlint:deprecation.
5052
*/
51-
val deprecation = ScalacOption("-deprecation", _ => true)
53+
val deprecation = ScalacOption(
54+
"-deprecation",
55+
version => version < V2_13_0 || version >= V3_0_0
56+
)
5257

5358
/** Emit warning and location for usages of features that should be imported explicitly.
5459
*/
@@ -241,6 +246,8 @@ private[scalacoptions] trait ScalacOptions {
241246
)
242247

243248
/** Enable linted deprecations.
249+
*
250+
* Added in 2.13.0, backported to 2.12.13.
244251
*/
245252
val lintDeprecation =
246253
lintOption("deprecation", version => version.isBetween(V2_12_13, V3_0_0))
@@ -656,9 +663,22 @@ private[scalacoptions] trait ScalacOptions {
656663
warnOption("numeric-widen", version => version.isBetween(V2_13_0, V3_0_0))
657664

658665
/** Warn when non-Unit expression results are unused.
666+
*
667+
* Added in 2.13.0, ported to 3.3.0.
659668
*/
660669
val warnValueDiscard =
661-
warnOption("value-discard", version => version.isBetween(V2_13_0, V3_0_0))
670+
warnOption(
671+
"value-discard",
672+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
673+
)
674+
675+
/** Warn when an expression is ignored because it is followed by another expression.
676+
*/
677+
val warnNonUnitStatement =
678+
warnOption(
679+
"nonunit-statement",
680+
version => version.isBetween(V2_13_9, V3_0_0)
681+
)
662682

663683
/** Fail the compilation if there are any warnings.
664684
*/
@@ -674,46 +694,81 @@ private[scalacoptions] trait ScalacOptions {
674694
ScalacOption(s"-Wunused:$name", isSupported)
675695

676696
/** Warn if a @nowarn annotation did not suppress at least one warning.
697+
*
698+
* Added in 2.13.2, backported to 2.12.13.
677699
*/
678700
val warnUnusedNoWarn =
679-
warnUnusedOption("nowarn", version => version.isBetween(V2_13_0, V3_0_0))
701+
warnUnusedOption(
702+
"nowarn",
703+
version => version.isBetween(V2_12_13, V2_13_0) || version.isBetween(V2_13_2, V3_0_0)
704+
)
680705

681706
/** Warn if an implicit parameter is unused.
707+
*
708+
* Added in 2.13.0, ported to 3.3.0.
682709
*/
683710
val warnUnusedImplicits =
684-
warnUnusedOption("implicits", version => version.isBetween(V2_13_0, V3_0_0))
711+
warnUnusedOption(
712+
"implicits",
713+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
714+
)
685715

686716
/** Warn if an explicit parameter is unused.
717+
*
718+
* Added in 2.13.0, ported to 3.3.0.
687719
*/
688720
val warnUnusedExplicits =
689-
warnUnusedOption("explicits", version => version.isBetween(V2_13_0, V3_0_0))
721+
warnUnusedOption(
722+
"explicits",
723+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
724+
)
690725

691726
/** Warn if an import selector is not referenced.
727+
*
728+
* Added in 2.13.0, ported to 3.3.0.
692729
*/
693730
val warnUnusedImports =
694-
warnUnusedOption("imports", version => version.isBetween(V2_13_0, V3_0_0))
731+
warnUnusedOption(
732+
"imports",
733+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
734+
)
695735

696736
/** Warn if a local definition is unused.
737+
*
738+
* Added in 2.13.0, ported to 3.3.0.
697739
*/
698740
val warnUnusedLocals =
699-
warnUnusedOption("locals", version => version.isBetween(V2_13_0, V3_0_0))
741+
warnUnusedOption(
742+
"locals",
743+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
744+
)
700745

701746
/** Warn if either explicit or implicit parameters are unused.
702747
*
703748
* Equivalent to -Wunused:explicits,implicits.
749+
*
750+
* Added in 2.13.0, ported to 3.3.0.
704751
*/
705752
val warnUnusedParams =
706-
warnUnusedOption("params", version => version.isBetween(V2_13_0, V3_0_0))
753+
warnUnusedOption(
754+
"params",
755+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
756+
)
707757

708758
/** Warn if a variable bound in a pattern is unused.
709759
*/
710760
val warnUnusedPatVars =
711761
warnUnusedOption("patvars", version => version.isBetween(V2_13_0, V3_0_0))
712762

713763
/** Warn if a private member is unused.
764+
*
765+
* Added in 2.13.0, ported to 3.3.0.
714766
*/
715767
val warnUnusedPrivates =
716-
warnUnusedOption("privates", version => version.isBetween(V2_13_0, V3_0_0))
768+
warnUnusedOption(
769+
"privates",
770+
version => version.isBetween(V2_13_0, V3_0_0) || version.isAtLeast(V3_3_0)
771+
)
717772

718773
/** Unused warning options (-Wunused:)
719774
*/
@@ -734,7 +789,8 @@ private[scalacoptions] trait ScalacOptions {
734789
warnDeadCode,
735790
warnExtraImplicit,
736791
warnNumericWiden,
737-
warnValueDiscard
792+
warnValueDiscard,
793+
warnNonUnitStatement
738794
) ++ warnUnusedOptions
739795

740796
/** Options which fail the compilation if there are any warnings.
@@ -744,6 +800,39 @@ private[scalacoptions] trait ScalacOptions {
744800
warnError
745801
)
746802

803+
/** Verbose options (-V)
804+
*/
805+
def verboseOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
806+
ScalacOption(s"-V$name", isSupported)
807+
808+
/** Print dependent missing implicits.
809+
*/
810+
val verboseImplicits =
811+
verboseOption("implicits", _.isBetween(V2_13_0, V3_0_0))
812+
813+
/** Print found/required error messages as colored diffs.
814+
*/
815+
val verboseTypeDiffs =
816+
verboseOption("type-diffs", _.isBetween(V2_13_6, V3_0_0))
817+
818+
/** Explain type errors in more detail.
819+
*/
820+
val explainTypes =
821+
ScalacOption("-explaintypes", _ < V3_0_0)
822+
823+
/** Explain errors in more detail.
824+
*/
825+
val explain = ScalacOption("-explain", _ >= V3_0_0)
826+
827+
/** Verbose options (-V)
828+
*/
829+
val verboseOptions: Set[ScalacOption] = ListSet(
830+
verboseImplicits,
831+
verboseTypeDiffs,
832+
explainTypes,
833+
explain
834+
)
835+
747836
/** The default set of Scala compiler options defined by sbt-tpolecat.
748837
*/
749838
val default: Set[ScalacOption] = ListSet(

0 commit comments

Comments
 (0)