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

Support Scalafix migrations that target build files #2308

Merged
merged 10 commits into from
Nov 1, 2021

Conversation

fthomas
Copy link
Member

@fthomas fthomas commented Oct 22, 2021

What has been done in this PR?

This PR extends the Scalafix support to run migrations with the Scalafix CLI in addition to sbt-scalafix. Migrations that are executed with the CLI target *.sbt and project/*.scala files in the build root directories. So these build migrations can change build files while regular sources migrations can change source files.

How?

To distinguish between sources and build migrations a new optional target field is added to ScalafixMigration. The default value is sources if this field is not specified. Scala Steward differentiate these two targets in SbtAlg and either calls the proper sbt command or the scalafix CLI. A new ScalafixCli class is added that takes care of running migrations with the CLI.

Want to see it in action?

This PR also adds @eed3si9n's Sbt0_13BuildSyntax for unified slash syntax to our list of Scalafix migrations:

{
groupId: "org.scala-sbt",
artifactIds: ["sbt"],
newVersion: "1.5.0",
rewriteRules: ["https://gist.githubusercontent.com/eed3si9n/57e83f5330592d968ce49f0d5030d4d5/raw/7f576f16a90e432baa49911c9a66204c354947bb/Sbt0_13BuildSyntax.scala"],
doc: "https://eed3si9n.com/syntactic-scalafix-rule-for-unified-slash-syntax",
authors: ["Eugene Yokota (eed3si9n) <eed3si9n@gmail.com>"]
target: "build"
},

which is used when sbt is bumped over 1.5.0. An example PR where the above migration was used and contains changes to build.sbt from Scalafix is:

The above PR also demonstrate another new feature: Co-authored-by: attribution of the Scalafix rule authors (#1914). @eed3si9n I added your name to the authors field above to test that feature but I'll only keep your name there if you're fine with this attribution in all future PRs where Scala Steward executes the Sbt0_13BuildSyntax rule.

Other notable changes

  • The Scalafix CLI has been added to the Docker image.
  • Scala Steward checks at start-up if it can run the Scalafix CLI and will print its version.

@fthomas fthomas linked an issue Oct 22, 2021 that may be closed by this pull request
@fthomas fthomas added this to the 0.13.0 milestone Oct 22, 2021
@fthomas fthomas added the enhancement New feature or request label Oct 22, 2021
@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #2308 (2519cdf) into master (8599b27) will increase coverage by 1.21%.
The diff coverage is 96.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2308      +/-   ##
==========================================
+ Coverage   78.45%   79.67%   +1.21%     
==========================================
  Files         136      137       +1     
  Lines        2349     2386      +37     
  Branches       58       59       +1     
==========================================
+ Hits         1843     1901      +58     
+ Misses        506      485      -21     
Impacted Files Coverage Δ
...steward/core/edit/scalafix/ScalafixMigration.scala 88.88% <80.00%> (-11.12%) ⬇️
...la/org/scalasteward/core/application/Context.scala 76.81% <100.00%> (-0.78%) ⬇️
...g/scalasteward/core/application/SelfCheckAlg.scala 100.00% <100.00%> (ø)
...a/org/scalasteward/core/buildtool/sbt/SbtAlg.scala 96.00% <100.00%> (+1.12%) ⬆️
.../scalasteward/core/edit/scalafix/ScalafixCli.scala 100.00% <100.00%> (ø)
.../main/scala/org/scalasteward/core/io/FileAlg.scala 97.05% <100.00%> (+0.08%) ⬆️
...lasteward/core/buildtool/BuildToolDispatcher.scala 100.00% <0.00%> (+23.07%) ⬆️
...ain/scala/org/scalasteward/core/edit/EditAlg.scala 94.44% <0.00%> (+25.00%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8599b27...2519cdf. Read the comment docs.

@fthomas fthomas marked this pull request as ready for review October 23, 2021 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scalafix-migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support syntactic Scalafix rules for migrating build files
1 participant