Skip to content

Commit 5fe9801

Browse files
committed
document how local rules can be built with Scala 3
1 parent 1c98afa commit 5fe9801

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,36 @@ inThisBuild(
1717
val rules = project
1818
.disablePlugins(ScalafixPlugin)
1919
.settings(
20-
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion,
20+
libraryDependencies +=
21+
("ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion)
22+
.cross(CrossVersion.for3Use2_13),
2123
libraryDependencies += "joda-time" % "joda-time" % "2.10.6"
2224
)
2325

2426
val service = project
2527
.dependsOn(rules % ScalafixConfig)
2628
.settings(
2729
// SyntacticRule
28-
libraryDependencies += "ch.epfl.scala" %% "example-scalafix-rule" % "3.0.0" % ScalafixConfig
30+
libraryDependencies +=
31+
("ch.epfl.scala" %% "example-scalafix-rule" % "3.0.0")
32+
.cross(CrossVersion.for3Use2_13) % ScalafixConfig
2933
)
3034

3135
// SameProjectSyntacticRule
3236
val sameproject = project
3337
.settings(
34-
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion % ScalafixConfig
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+
}
3552
)
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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
16
> service / scalafix LocalSyntacticRule
27

3-
# ensure updates to the rule definition (that we make sure compiles first) is reflected in the next run
4-
> rules / Test / compile
5-
$ copy-file rules/src/test/scala/local/Boom.scala rules/src/main/scala/local/Boom.scala
6-
$ delete rules/src/main/scala/local/NoOp.scala
7-
-> service / scalafix LocalSyntacticRule
8+
# run a rule defined in ScalafixConfig
9+
> sameproject / scalafix SameProjectSyntacticRule
810

911
# make sure scalafixDependencies is also honored by running a rule from a remote JAR
1012
> service / scalafix CollectHead
1113

1214
# run a rule included from a remote JAR referenced via the Scalafix ivy config
1315
> service / scalafix SyntacticRule
1416

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
1523
> 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)