Skip to content
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

Merged
merged 2 commits into from
Jun 14, 2020
Merged

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Jun 13, 2020

Docs companion: scalacenter/scalafix#1160

Similarly to scalafmtAll (except that the implementation here is more tricky as we deal with an InputTask 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 existing scalafix, 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 a scalafixAll invocation, and getting rid of a workaround.

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] =
Copy link
Collaborator Author

@bjaglin bjaglin Jun 13, 2020

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.

@bjaglin bjaglin changed the title Introduce scalafixAll WIP Introduce scalafixAll Jun 13, 2020
* 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
@bjaglin bjaglin changed the title WIP Introduce scalafixAll Introduce scalafixAll Jun 13, 2020
@bjaglin bjaglin marked this pull request as ready for review June 13, 2020 10:33
@bjaglin bjaglin changed the title Introduce scalafixAll Introduce scalafixAll InputTask Jun 13, 2020
Copy link
Contributor

@olafurpg olafurpg left a 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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants