-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial support for running rules on Scala 3 sources
- use sbt 1.3+ SemanticdbPlugin to offload the choice of the right compiler options to get semanticdb output from the compiler or the compiler plugin (with the right semanticdb and Scala full version) depending on the Scala binary version - extend SemanticRuleValidator to detect Scala 3 compiler flag injected by SemanticdbPlugin - always pass the scala version for scalafix to parse with the right dialect
- Loading branch information
1 parent
dcaed38
commit 5e14eb5
Showing
17 changed files
with
177 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/scala/scalafix/internal/sbt/SemanticdbPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package scalafix.internal.sbt | ||
|
||
import sbt._ | ||
|
||
import scala.util.Try | ||
|
||
/** Helper to use sbt 1.3+ SemanticdbPlugin features when available */ | ||
object SemanticdbPlugin { | ||
|
||
// Copied from https://github.com/sbt/sbt/blob/v1.3.0/main/src/main/scala/sbt/Keys.scala#L190-L195 | ||
val semanticdbEnabled = settingKey[Boolean]("") | ||
val semanticdbVersion = settingKey[String]("") | ||
|
||
lazy val available = Try { | ||
Class.forName("sbt.plugins.SemanticdbPlugin") | ||
true | ||
}.getOrElse(false) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scalaVersion := "3.0.0-RC3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resolvers += Resolver.sonatypeRepo("public") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) | ||
|
||
//FIXME: remove when scalafixVersion is bumped to 0.9.28 | ||
resolvers += Resolver.sonatypeRepo("snapshots") | ||
dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "0.9.27+52-6c9eeec9-SNAPSHOT" |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbt-1.5/scala-3/src/main/scala/SignificantIndentation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object SignificantIndentation: | ||
implicit class XtensionVal(val str: String) extends AnyVal: | ||
def doubled: String = str + str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# check that we can run a syntactic rule against a Scala 3 dialect source file | ||
-> scalafix --check LeakingImplicitClassVal | ||
> scalafix LeakingImplicitClassVal | ||
> scalafix --check LeakingImplicitClassVal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ThisBuild / scalafixDependencies += "ch.epfl.scala" %% "example-scalafix-rule" % "1.6.0" | ||
|
||
lazy val scala210 = project | ||
.in(file("scala210")) | ||
.settings( | ||
scalaVersion := "2.10.7" // unsupported by semanticdb-scalac | ||
) | ||
|
||
lazy val scala211 = project | ||
.in(file("scala211")) | ||
.settings( | ||
scalaVersion := "2.11.12" // supported by semanticdb-scalac | ||
) | ||
|
||
lazy val scala3 = project | ||
.in(file("scala3")) | ||
.settings( | ||
scalaVersion := "3.0.0-RC3" // built-in support for semanticdb | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resolvers += Resolver.sonatypeRepo("public") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) | ||
|
||
//FIXME: remove when scalafixVersion is bumped to 0.9.28 | ||
resolvers += Resolver.sonatypeRepo("snapshots") | ||
dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "0.9.27+52-6c9eeec9-SNAPSHOT" |
7 changes: 7 additions & 0 deletions
7
src/sbt-test/sbt-1.5/scalafixEnable/scala210/src/main/scala/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object Main { | ||
def foo(a: (Int, String)) = a | ||
foo(1, "str") | ||
def main(args: Array[String]) { | ||
println(1) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/sbt-test/sbt-1.5/scalafixEnable/scala211/src/main/scala/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object Main { | ||
def foo(a: (Int, String)) = a | ||
foo(1, "str") | ||
def main(args: Array[String]) { | ||
println(1) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/sbt-test/sbt-1.5/scalafixEnable/scala3/src/main/scala/SignificantIndentation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
object SignificantIndentation: | ||
val hello = "world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# enable semanticdb output where supported | ||
> scalafixEnable | ||
|
||
# check that projects not supported by semanticdb-scalac can still compile | ||
> scala210/compile | ||
|
||
# check that we can run a semantic rule against a Scala 2.11 dialect source file | ||
-> scala211/scalafix --check SemanticRule | ||
> scala211/scalafix SemanticRule | ||
> scala211/scalafix --check SemanticRule | ||
|
||
# check that we can run a semantic rule against a Scala 3 dialect source file | ||
-> scala3/scalafix --check SemanticRule | ||
> scala3/scalafix SemanticRule | ||
> scala3/scalafix --check SemanticRule |