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

add scalafix rule to migrate code from Typesafe Config to sconfig #191

Merged
merged 6 commits into from
Aug 26, 2021
Merged

add scalafix rule to migrate code from Typesafe Config to sconfig #191

merged 6 commits into from
Aug 26, 2021

Conversation

bpholt
Copy link
Contributor

@bpholt bpholt commented Aug 25, 2021

after publishing, this would be executed by running

scalafix dependency:ReplaceTypesafeConfig@org.ekrich:sconfig-scalafix:1.4.5

This rule is just a starting point. I think theoretically it could be added to over time, to support additional rewrites like removing the empty parens from certain method calls, etc.

after publishing, this would be executed by running

```
scalafix dependency:ReplaceTypesafeConfig@org.ekrich:sconfig-scalafix:1.4.5
```
@ekrich
Copy link
Owner

ekrich commented Aug 25, 2021

@bpholt I am not all that familiar with Scalafix but typesafe config is Java and this project is Scala. See lightbend/config#600

I think any changes need to be ported by hand.

@bpholt
Copy link
Contributor Author

bpholt commented Aug 25, 2021

Sorry, I should have given more context. This is intended to be used in a Scala codebase that was originally written using the Java library and wants to convert to sconfig.

Scalafix lets one define rewrite rules / refactorings that can modify a project's source code—it's often used to aid upgrades across versions that have source incompatibilities. For example, http4s uses it to rewrite package names when they moved things around.

I added some tests which I think also demonstrate how this would be used—see scalafix/input/src/main/scala/org/ekrich/example/Foo.scala, which is Scala code written using Typesafe Config, vs scalafix/output/src/main/scala/org/ekrich/example/Foo.scala, which is the same code, but with the rewrites applied so that it works with sconfig.

@ekrich
Copy link
Owner

ekrich commented Aug 25, 2021

So I guess what you are saying that I publish this Scalafix rule to Maven. Then a user would use this rule by adding it to their sbt file so they could migrate their Scala codebase from Typesafe config (Java) to sconfig?

There was this issue but never had time to investigate - #67

@bpholt
Copy link
Contributor Author

bpholt commented Aug 25, 2021

As we discussed in Discord, I'm going to add some documentation on how to use this to the readme.

Copy link
Owner

@ekrich ekrich left a comment

Choose a reason for hiding this comment

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

I made suggestions just to be really clear about what I was thinking but feel free to improve the wording. Just would like to avoid updating as versions change. A scalafix tag from Maven would probably be better but I just thought of that.

Please make the changes yourself so I won't be a co-author as you deserve all the credit.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@ekrich
Copy link
Owner

ekrich commented Aug 26, 2021

Something went batty above - sorry.

@bpholt
Copy link
Contributor Author

bpholt commented Aug 26, 2021

My understanding is that all the processing for badges happens on the backend—from the perspective of the README markdown, they're just images included in the page. (The corollary being that sometimes there are caching issues and the badges don't update right away when new versions are published.)

I think I updated the readme with all your suggestions, but let me know if I missed anything!

@bpholt bpholt requested a review from ekrich August 26, 2021 04:32
Copy link
Owner

@ekrich ekrich left a comment

Choose a reason for hiding this comment

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

I am trying to wrap my head around versionsBase. It seems that this capability is only applicable to JVM projects so if we need to publish all the Scala versions then it should be versionsJVM assuming this will work on Scala 3 codebases.

@bpholt
Copy link
Contributor Author

bpholt commented Aug 26, 2021

I am trying to wrap my head around versionsBase. It seems that this capability is only applicable to JVM projects so if we need to publish all the Scala versions then it should be versionsJVM assuming this will work on Scala 3 codebases.

That's where I started, but it didn't seem like Scalafix was published for Scala 3 yet—at least not on Maven Central. (Their website describes Scalafix for Scala 3 as "experimental" and says not everything works yet.) I figured it was good enough to start with the Scala 2 versions and then we can add Scala 3 once Scalafix supports it better.

@ekrich
Copy link
Owner

ekrich commented Aug 26, 2021

@bpholt LGTM - thanks for your contribution.

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.

None yet

2 participants