Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Respect Configuration in scalafixConfigSettings #154

Merged
merged 4 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,26 @@ object ScalafixPlugin extends AutoPlugin {
"org.scalameta" % "semanticdb-scalac" % scalametaVersion cross CrossVersion.full

def scalafixConfigSettings(config: Configuration): Seq[Def.Setting[_]] =
Seq(
scalafix := scalafixInputTask(config).evaluated,
compile := Def.taskDyn {
val oldCompile =
compile.value // evaluated first, before the potential scalafix evaluation
if (scalafixOnCompile.value)
scalafix
.toTask("")
.map(_ => oldCompile)
else Def.task(oldCompile)
}.value,
// In some cases (I haven't been able to understand when/why, but this also happens for bgRunMain while
// fgRunMain is fine), there is no specific streams attached to InputTasks, so we they end up sharing the
// global streams, causing issues for cache storage. This does not happen for Tasks, so we define a dummy one
// to acquire a distinct streams instance for each InputTask.
scalafixDummyTask := (()),
streams.in(scalafix) := streams.in(scalafixDummyTask).value
inConfig(config)(
Seq(
scalafix := scalafixInputTask(config).evaluated,
compile := Def.taskDyn {
val oldCompile =
compile.value // evaluated first, before the potential scalafix evaluation
if (scalafixOnCompile.value)
scalafix
.toTask("")
.map(_ => oldCompile)
else Def.task(oldCompile)
}.value,
// In some cases (I haven't been able to understand when/why, but this also happens for bgRunMain while
// fgRunMain is fine), there is no specific streams attached to InputTasks, so we they end up sharing the
// global streams, causing issues for cache storage. This does not happen for Tasks, so we define a dummy one
// to acquire a distinct streams instance for each InputTask.
scalafixDummyTask := (()),
streams.in(scalafix) := streams.in(scalafixDummyTask).value
)
)

@deprecated("This setting is no longer used", "0.6.0")
val scalafixSourceroot: SettingKey[File] =
settingKey[File]("Unused")
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/basic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ inThisBuild(
lazy val example = project
.settings(
Defaults.itSettings,
inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)),
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= List(
"-Yrangepos",
"-Ywarn-unused-import"
)
)
.settings(scalafixConfigSettings(IntegrationTest): _*)

lazy val tests = project

Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/sbt-scalafix/cross-build/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ lazy val scala212 = project
.configs(IntegrationTest)
.settings(
Defaults.itSettings,
inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)),
unmanagedSources.in(Compile, scalafix) :=
unmanagedSources
.in(Compile)
Expand All @@ -41,6 +40,8 @@ lazy val scala212 = project
scalaVersion := Versions.scala212,
scalafixSettings
)
.settings(scalafixConfigSettings(IntegrationTest): _*)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inConfig seems to return the same type as scalafixConfigSettings, is there a reason why you moved down all the settings and used the spread operator? it would be nicer if we could keep them inline (for the diff, but mostly for users!)


lazy val javaProject = project.settings(
scalaVersion := Versions.scala212,
scalafixSettings
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/inconfig/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ inThisBuild(
lazy val example = project
.settings(
Defaults.itSettings,
inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)),
addCompilerPlugin(scalafixSemanticdb),
scalacOptions += "-Yrangepos"
)
.settings(scalafixConfigSettings(IntegrationTest): _*)

lazy val tests = project
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/scalafixOnCompile/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ lazy val rewrite = project
.configs(IntegrationTest)
.settings(
Defaults.itSettings,
inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)),
addCompilerPlugin(scalafixSemanticdb)
)
.settings(scalafixConfigSettings(IntegrationTest): _*)