Skip to content

Commit

Permalink
support running scalafix on projects with sources at the root
Browse files Browse the repository at this point in the history
When defining local rules using the Scalafix configuration,
libraryDependencies must be defined, as documented in:
https://scalacenter.github.io/scalafix/docs/developers/local-rules.html.
We could add it by default, but it would unnecessarily clutter the
update task in 99.9% of the plugin use cases.

When projects have a custom directory layout (via scalaSource), users
could not know that Scalafix settings would need to be updated to exclude
sources potentially at the root (sourcesInBase), in order to prevent
compilation errors as Scalafix does not have the Scala libs, causing:

> scala.reflect.internal.MissingRequirementError: object scala in
> compiler mirror not found.

This commit disables sourcesInBase by default to prevent this, as the
local rules have no reason to share code with other default
configurations anyway.
  • Loading branch information
github-brice-jaglin committed Dec 2, 2020
1 parent 9b6b3b9 commit 1c9268b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ object ScalafixPlugin extends AutoPlugin {

override lazy val projectSettings: Seq[Def.Setting[_]] =
Seq(Compile, Test).flatMap(c => inConfig(c)(scalafixConfigSettings(c))) ++
inConfig(ScalafixConfig)(Defaults.configSettings) ++
inConfig(ScalafixConfig)(
Defaults.configSettings :+ (sourcesInBase := false)
) ++
Seq(
ivyConfigurations += ScalafixConfig,
scalafixAll := scalafixAllInputTask.evaluated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object ProcedureSyntax {
def unit {}
}
3 changes: 3 additions & 0 deletions src/sbt-test/sbt-scalafix/custom-src-directory/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val app = project.settings(
scalaSource.in(Compile) := baseDirectory.value
)
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 src/sbt-test/sbt-scalafix/custom-src-directory/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-> app/scalafix --test ProcedureSyntax
> app/scalafix ProcedureSyntax
> app/scalafix --test ProcedureSyntax

0 comments on commit 1c9268b

Please sign in to comment.