-
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.
Users can control whether scalafix (running the default rules declared in .scalafix.conf) should be run as part of `compile` at the project & configuration level. The value of scalafixOnCompile is ignored when invoking directly scalafix or scalafixAll, as the CLI arguments (if there are any) take precedence over the default rules. That means for example that `scalafix --check` is safe to run even though scalafixOnCompile := true, as there will not be any rewrite triggered by the implicit compilation.
- Loading branch information
1 parent
3800f16
commit 0cf5501
Showing
8 changed files
with
103 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rules = [DisableSyntax, RemoveUnused] | ||
DisableSyntax.noNulls = true |
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,23 @@ | ||
import _root_.scalafix.sbt.{BuildInfo => Versions} | ||
|
||
inThisBuild( | ||
Seq( | ||
scalaVersion := Versions.scala212, | ||
scalacOptions ++= List( | ||
"-Yrangepos", | ||
"-Ywarn-unused-import" | ||
) | ||
) | ||
) | ||
lazy val lint = project | ||
.settings( | ||
addCompilerPlugin(scalafixSemanticdb) | ||
) | ||
|
||
lazy val rewrite = project | ||
.configs(IntegrationTest) | ||
.settings( | ||
Defaults.itSettings, | ||
inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)), | ||
addCompilerPlugin(scalafixSemanticdb) | ||
) |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbt-scalafix/scalafixOnCompile/lint/src/test/scala/Null.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 Null { | ||
println(null) | ||
} |
2 changes: 2 additions & 0 deletions
2
src/sbt-test/sbt-scalafix/scalafixOnCompile/project/plugins.sbt
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 @@ | ||
resolvers += Resolver.sonatypeRepo("public") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbt-scalafix/scalafixOnCompile/rewrite/src/it/scala/UnusedImports.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 @@ | ||
import java.time.Instant | ||
|
||
object UnusedImports |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/sbt-scalafix/scalafixOnCompile/rewrite/src/main/scala/UnusedImports.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 @@ | ||
import java.time.Instant | ||
|
||
object UnusedImports |
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,26 @@ | ||
# check implicit rewrite of rewrite/src/main/scala/UnusedImports.scala via `compile` | ||
> compile | ||
-> scalafix --check | ||
> set scalafixOnCompile.in(ThisBuild) := true | ||
-> scalafix --check | ||
> compile | ||
> scalafix --check | ||
|
||
# check explicit rewrite of rewrite/src/it/scala/UnusedImports.scala via `scalafix` | ||
-> it:scalafix --check | ||
> it:scalafix | ||
> it:scalafix --check | ||
|
||
# check lint for lint/src/test/scala/Null.scala | ||
-> lint/test:scalafix --check | ||
-> lint/test:scalafix | ||
-> lint/test:compile | ||
|
||
# check that default rules are ignored when rules are passed explicitly | ||
-> lint/test:scalafix --check | ||
> lint/test:scalafix --check RemoveUnused | ||
> lint/test:scalafix RemoveUnused | ||
|
||
# check configuration granularity for scalafixOnCompile | ||
> set scalafixOnCompile.in(lint, Test) := false | ||
> lint/test:compile |