Skip to content

Commit d54f51b

Browse files
authored
Merge pull request #481 from bjaglin/scala3-local-rules
test/document how local rules can be written against Scala 3
2 parents 3de37a3 + fd0f76f commit d54f51b

File tree

13 files changed

+79
-47
lines changed

13 files changed

+79
-47
lines changed

src/sbt-test/sbt-scalafix/local-rules/build.sbt

-32
This file was deleted.

src/sbt-test/sbt-scalafix/local-rules/test

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import _root_.scalafix.sbt.{BuildInfo => Versions}
2+
3+
inThisBuild(
4+
List(
5+
scalafixDependencies := List(
6+
// CollectHead
7+
"com.github.xuwei-k" %% "scalafix-rules" % "0.6.5"
8+
),
9+
resolvers += Resolver.sonatypeRepo("snapshots"),
10+
// out of sync with scalafix.sbt.BuildInfo.scala213 on purpose
11+
scalaVersion := "2.13.11",
12+
Compat.allowUnsafeScalaLibUpgrade := true
13+
)
14+
)
15+
16+
// LocalSyntacticRule
17+
val rules = project
18+
.disablePlugins(ScalafixPlugin)
19+
.settings(
20+
libraryDependencies +=
21+
("ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion)
22+
.cross(CrossVersion.for3Use2_13),
23+
libraryDependencies += "joda-time" % "joda-time" % "2.10.6"
24+
)
25+
26+
val service = project
27+
.dependsOn(rules % ScalafixConfig)
28+
.settings(
29+
// SyntacticRule
30+
libraryDependencies +=
31+
("ch.epfl.scala" %% "example-scalafix-rule" % "3.0.0")
32+
.cross(CrossVersion.for3Use2_13) % ScalafixConfig
33+
)
34+
35+
// SameProjectSyntacticRule
36+
val sameproject = project
37+
.settings(
38+
libraryDependencies +=
39+
("ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion)
40+
.cross(CrossVersion.for3Use2_13) % ScalafixConfig,
41+
// Since sbt 1.10.x (https://github.com/sbt/sbt/pull/7480), scala3-library is not automatically added
42+
// to non-standard configurations, but is needed by the Scala 3 compiler, so it must be added explicitly
43+
// if no dependency brings it implicitly, which is the case here because the only dependency is for3Use2_13.
44+
libraryDependencies ++= {
45+
if (scalaBinaryVersion.value == "3")
46+
Seq(
47+
"org.scala-lang" %% "scala3-library" % scalaVersion.value % ScalafixConfig
48+
)
49+
else
50+
Nil
51+
}
52+
)
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# try to run a failing local rule without prior explicit rule compilation
2+
-> service / scalafix LocalSyntacticRule
3+
4+
# ensure updates to the rule definition is reflected in the next run
5+
$ copy-file rules/src/test/scala/local/NoOp.scala rules/src/main/scala/local/Syntactic.scala
6+
> service / scalafix LocalSyntacticRule
7+
8+
# run a rule defined in ScalafixConfig
9+
> sameproject / scalafix SameProjectSyntacticRule
10+
11+
# make sure scalafixDependencies is also honored by running a rule from a remote JAR
12+
> service / scalafix CollectHead
13+
14+
# run a rule included from a remote JAR referenced via the Scalafix ivy config
15+
> service / scalafix SyntacticRule
16+
17+
18+
# switch all projects to Scala 3 to ...
19+
> set ThisBuild / scalaVersion := "3.6.4"
20+
21+
# ... test that local rules can be written in Scala 3 ...
22+
> service / scalafix LocalSyntacticRule
23+
> sameproject / scalafix SameProjectSyntacticRule
24+
25+
# ... while still supporting community rules written against Scala 2.13 (until https://github.com/scalacenter/scalafix/issues/2041)
26+
> service / scalafix CollectHead
27+
> service / scalafix SyntacticRule

0 commit comments

Comments
 (0)