-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Scalafix rule to remove instance imports when upgrading to 2.2.0 #3566
Conversation
The import is only removed if there is no possibility it is being used to import Future instances.
Upgrading it broke one of the v1.0.0 rules and I can't be bothered investigating
The v1.0.0 expected output files won't compile without this.
Codecov Report
@@ Coverage Diff @@
## master #3566 +/- ##
==========================================
+ Coverage 91.27% 91.31% +0.04%
==========================================
Files 386 386
Lines 8593 8617 +24
Branches 255 243 -12
==========================================
+ Hits 7843 7869 +26
+ Misses 750 748 -2 |
This looks good to me, with a couple of comments. Can you give more details about this?
Also the fact that there's so much special-casing needed here for the |
The failing test is the one for the It looks like something in the behaviour of scalafix/scalameta changed between sbt-scalafix 0.9.16 and 0.9.17. The expected value no longer appears in the denotation, so the rule never applies any patches. I had a quick look at the scalafix and scalameta changelogs but couldn't find a likely culprit for the change. In the grand scheme of things I don't think this is very important - how many people out there are still running Cats v0.9 and looking to migrate to 1.0.0, and make use of
I don't have a strong opinion on whether the Future instances should remain in core or move to alleycats, especially as I rarely use Future myself. I know this has been discussed at length and I don't really have any insight to add. But I think keeping them in core but leaving them out of implicit scope, just for the sake of making them a second class citizen, is probably the worst of both worlds. It'll confuse people and lead to increased support burden on gitter. I would suggest we add them to implicit scope for v2.2.0, and you lobby to get them moved to alleycats in v3.0.0. |
I was just looking at the I'm still definitely open to discussion about these instances, but I think this is a real reason to exclude them from implicit scope that isn't just "nobody really likes them". |
I see. If there’s a valid technical reason not to add them, that’s fair enough. In that case I guess there are no changes needed on this PR? |
assuming (if there are no oversights) that Future's instances are the only one left out of scope, I was wondering if a possible strategy could be to replace the import with
instead of leaving there |
Good idea. That should be pretty easy to do. I was also wondering whether, in the case that |
I'm in favor of the Future instances being implicitly available. |
Yeah I agree with @mpilquist we should add them to cats-kernel |
This is so we get Future instances in implicit scope
I've updated the rule in light of Future instances now being available in implicit scope, so this is ready for another review. Also updated the PR description to match the new behaviour. |
i.e. imports at the top of the file
6bca848
@fthomas I think you ran into scalacenter/scalafix#1123. I don't think there's much we can do about it, but as a workaround I added a try-catch to log it when it happens and stop it from crashing scalafix. Also added another test. |
Thanks for adding the workaround, @cb372! I'll try out the new version again ASAP. |
@cb372 The scalafix now succeeds but the build still fails because some imports of
Adding |
a1b8d09 fixed 100 errors in my test, only 9 errors are remaining. They are all similar to this (source file):
In this file |
Do not remove an import of cats.implicits._ if it is being used to import an implicit conversion
@fthomas your build should pass this time 🤞 |
Yes it did! Many thanks for the quick fixes, @cb372! ❤️ |
* Allow setting compiler options for Scalafix migrations In anticipation to typelevel/cats#3566 * Use Option#fold and change order of fields * Test migration with scalacOptions * Use Option.when in sbtDependency
This rule can now be tested really easily by anyone who is using Scala Steward: just bump Cats to 2.2.0-RC3 and Scala Steward will use this rule for the update to 2.2.0-RC4. My tests with refined (fthomas/refined#804) and scala-steward (scala-steward-org/scala-steward#1590) were successful. |
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.
@travisbrown Yep, I'd say this is ready to merge Sorry I think I confused the GitHub check by putting |
52e9511
to
57d08ac
Compare
You can use this query to get a list of all migrations done by Scala Steward to cats |
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 pretty cool, thanks!
Fixes #3563
A Scalafix rule for removing instance imports that become unnecessary in v2.2.0 thanks to #3043
Behaviour is as follows:
import cats.instances.foo._
import cats.implicits._
import cats.syntax.all._
if there is any use of a syntax extension method within the lexical range of the import statementWhat I mean by "lexical range" is the range where the import statement can affect lexical scope, i.e. from the end of the import statement to the end of its enclosing block, method body or class/object body. Not sure if there's an accepted name for this.
Other changes
Bumped sbt-scalafix to the latest version<- Gave up on this is as it caused one of the existing rules to break. Let's save that for another PR.