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

Load Scalafix migrations once at start-up #1309

Merged
merged 5 commits into from
Feb 11, 2020
Merged

Conversation

fthomas
Copy link
Member

@fthomas fthomas commented Feb 10, 2020

This changes a few things about the loading of Scalafix migrations:

  • Default Scalafix migrations are now defined in a new scalafix-migrations.conf file that are packaged in the JAR as resource. @kubukoz proposed this idea in Support custom group migrations #1298 (comment) for groupId changes. A big benefit is that default Scalafix migrations are defined in the same format as user-supplied migrations.

  • All Scalafix migrations are now loaded at start-up and a decoding error will lead to Scala Steward exiting immediately. This way we provide rapid feedback if the migrations file contains syntax errors and we avoid repeatedly loading the same migrations again and again.

  • HOCON is used as file format for Scalafix migrations. I think this is better suited for files that are written by humans since it allows comments for example. If someone feels strongly about this, I can be persuaded to change it back to JSON.

@fthomas fthomas added this to the 0.6.0 milestone Feb 10, 2020
@fthomas fthomas added the enhancement New feature or request label Feb 10, 2020
@codecov
Copy link

codecov bot commented Feb 10, 2020

Codecov Report

Merging #1309 into master will decrease coverage by 0.1%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1309      +/-   ##
=========================================
- Coverage    67.3%   67.2%   -0.11%     
=========================================
  Files          98      98              
  Lines        1557    1494      -63     
  Branches       52      50       -2     
=========================================
- Hits         1048    1004      -44     
+ Misses        509     490      -19
Impacted Files Coverage Δ
.../main/scala/org/scalasteward/core/io/package.scala 92.85% <ø> (-0.48%) ⬇️
...ala/org/scalasteward/core/nurture/NurtureAlg.scala 6.52% <0%> (-2.26%) ⬇️
.../main/scala/org/scalasteward/core/io/FileAlg.scala 80% <100%> (+0.83%) ⬆️
.../main/scala/org/scalasteward/core/sbt/SbtAlg.scala 94.44% <100%> (ø) ⬆️
...calasteward/core/vcs/data/NewPullRequestData.scala 100% <100%> (ø) ⬆️
.../org/scalasteward/core/scalafix/MigrationAlg.scala 94.73% <100%> (+0.61%) ⬆️
.../scala/org/scalasteward/core/vcs/VCSExtraAlg.scala 100% <100%> (+20%) ⬆️
...main/scala/org/scalasteward/core/sbt/package.scala 90.9% <100%> (ø) ⬆️
...main/scala/org/scalasteward/core/vcs/package.scala 100% <100%> (ø) ⬆️
... and 2 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 eb90c70...7a1cede. Read the comment docs.

@kubukoz
Copy link
Contributor

kubukoz commented Feb 10, 2020

This means if anyone used to pass JSON files with scalafix config, their files will no longer work, right? Or is JSON a valid subset of HOCON?


def readResource[F[_]](resource: String)(implicit F: Sync[F]): F[String] =
Resource
.fromAutoCloseable(F.delay(Source.fromResource(resource)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I didn't know about Source.fromResource!

Resource
.fromAutoCloseable(IO(Source.fromResource(s"org/scalasteward/plugin/$name")))
.use(src => IO(FileData(name, src.mkString)))
io.readResource[IO](s"org/scalasteward/plugin/$name")
Copy link
Contributor

Choose a reason for hiding this comment

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

show?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a big fan of the Show type class and I don't think we use show anywhere else in the code base. If we would have an interpolator that ensures the interpolated value is a String, I'd use it here and probably everywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, let's keep it with s then :)

@fthomas
Copy link
Member Author

fthomas commented Feb 10, 2020

@kubukoz Yes, JSON is a subset of HOCON, see https://github.com/lightbend/config/blob/master/HOCON.md#goals--background:

a JSON superset, that is, all valid JSON should be valid and should result in the same in-memory data that a JSON parser would have produced.

But I changed the name of the key extraMigrations to just migrations. So at least this needs to updated.

@kubukoz
Copy link
Contributor

kubukoz commented Feb 10, 2020

:shipit:

@kubukoz
Copy link
Contributor

kubukoz commented Feb 10, 2020

I'm waiting for this with #1298 because I had to rebase to borrow readResource :D

def readResource[F[_]](resource: String)(implicit F: Sync[F]): F[String] =
Resource
.fromAutoCloseable(F.delay(Source.fromResource(resource)))
.use(src => F.delay(src.mkString))
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this will block (maybe fromResource too)... shall we add Blocker here?

@fthomas fthomas merged commit 2147c92 into master Feb 11, 2020
@fthomas fthomas deleted the topic/load-migrations-once branch February 12, 2020 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants