-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce scalafixAll InputTask #126
Conversation
sbt/sbt#3572 shows that the macro behind inputTaskDyn is too restrictive, so this is bypassing it, to use directly the helpers that the macro would generate if it was less permissive.
private var scalafixInterface: () => ScalafixInterface = | ||
() => throw new UninitializedError | ||
|
||
private val scalafixInterface: Def.Initialize[() => ScalafixInterface] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By being a Setting
, the function wrapped here is instantiated at sbt load time (capturing other global scalafix*
settings) as it's referenced by scalafix[All]InputTask
through parser
, but evaluated at task execution time, and since it's backed by a LazyValue
, it's memoized.
* explicitly scope all value lookups to the current configuration in order to prevent scalafixAll from lookuping up in the Zero config * make sure scalafix and scalafixAll share the same cache for a given configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic! LGTM 👍
@@ -158,20 +170,49 @@ object ScalafixPlugin extends AutoPlugin { | |||
|
|||
} | |||
|
|||
private def scalafixAllInputTask(): Def.Initialize[InputTask[Unit]] = | |||
// workaround https://github.com/sbt/sbt/issues/3572 by invoking directly what Def.inputTaskDyn would via macro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome to see a workaround for this issue, nice job tracking down the issue!
@@ -205,6 +205,24 @@ $ exec chmod 000 src/test/scala/Valid.scala | |||
$ delete src/main/scala | |||
$ delete src/test/scala | |||
|
|||
# scalafixAll and scalafix should share the same cache per configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
Docs companion: scalacenter/scalafix#1160
Similarly to
scalafmtAll
(except that the implementation here is more tricky as we deal with anInputTask
for which.all
does not work), this allows a user to easily and efficiently run Scalafix across configurations for a given project (or of course for all projects/configurations with root project aggregation)I saw there were previous discussions/opinions about that (I should have opened an issue to discuss that beforehand). From my side I see no reason not to do it, especially because implementation is hard(er) downstream but simple here (or at least readable & compact), and because it allows
scalafix --check
to run in parallel over all configurations (rather than in sequential as documented in https://scalacenter.github.io/scalafix/docs/users/installation.html#enforce-in-ci), so it's not just sugar.There has already been work downstream to bring that to users through a command (like https://github.com/alejandrohdezma/sbt-fix#running-scalafix-in-all-configurations), but refactoring the code here allows us to expose an
InputTask
, with the same auto-completion as the existingscalafix
, which can't be done downstream at the moment.The first commit is preliminary, separating parsing & core logic from
scalafix
so that the output of the parser is reused across configurations during ascalafixAll
invocation, and getting rid of a workaround.