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

document sbt-scalafix scalafixScalaBinaryVersion #1166

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Jun 16, 2020

Merge only when scalacenter/sbt-scalafix#121 is released

Improves #998

@@ -155,6 +155,8 @@ Great! You are all set to use Scalafix with sbt :)
| `scalafixConfig` | `SettingKey[Option[File]]` | `.scalafix.conf` file to specify which scalafix rules should run, together with their potential options. Defaults to `.scalafix.conf` in the root directory, if it exists.
| `scalafixDependencies` | `SettingKey[Seq[ModuleID]]` | Dependencies making [custom rules](#run-custom-rules) available via their simple name. Must be set in `ThisBuild`. Defaults to `Nil`.
| `scalafixResolvers` | `SettingKey[Seq[Repository]]` | Custom resolvers where `scalafixDependencies` are resolved from. Must be set in `ThisBuild`. Defaults to: Ivy2 local, Maven Central, Sonatype releases & Sonatype snapshots.
| `scalafixScalaBinaryVersion` | `SettingKey[String]` | Scala binary version used for Scalafix execution. Defaults to 2.12. For advanced rules such as ExplicitResultTypes to work, it must match the binary version defined in the build for compiling sources. Note that `scalafixDependencies` artifacts must be published against that Scala version.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that scalafixDependencies artifacts must be published against that Scala version.

That's a bit vague on purpose, as I didn't want to explain which full Scala version would be used in case we have external rules using the presentation compiler.

Comment on lines 62 to 65
s"The ExplicitResultTypes rule only supports the Scala version '$supportedScalaVersion' for this Scala " +
"binary version. To fix this problem, either remove `ExplicitResultTypes` from .scalafix.conf, or adjust " +
s"the patch Scala version in your build to match exactly '$supportedScalaVersion' after making sure that " +
s"the `scalafixBinaryScalaVersion` setting key matches the Scala binary version of your build."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not very happy about that as the first sentence can be confusing when binary scala version does not match.... Ideally, we should get supportedScalaVersion from scalafix-cli based on config.scalaVersion, but that's impossible. Any suggestion is welcome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After re-reading scalacenter/sbt-scalafix#121 (comment), I was wondering if we could simply remove the full version constraint here and focus on the binary version (maybe by cross-testing rules at the patch level to verify compatibility)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand exactly what you mean, but I agree that now this rule could be used for 2.11, 2.12, and 2.13..
You would like to test many version of the same 2.13 ??

Copy link
Collaborator Author

@bjaglin bjaglin Jun 19, 2020

Choose a reason for hiding this comment

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

Currently, the rule will fail verbosely if the sources were compiled with a different patch version than the one scalafix-rules was built against.

It's either:

  1. a different patch version, in which case the user must update its built version to match the one from scalafix-rules
  2. a different binary version, in which case the user must align the scalafixScalaBinaryVersion AND potentially the patch release as in (1). The first sentence is a bit confusing as it will say "The ExplicitResultTypes rule only supports the Scala version 2.12.11" for sources compiled in 2.13.1 for example, which is not true as there is now support for 2.13.2.

That's why I was wondering if we should relax the constraint to only fail on a binary version mismatch, and assume it will work most of the time for patch version mismatch. That's my interpretation of @olafurpg's comment. In that case, it might be wise to run the testkit against input cross-built against many patch versions (and not just one per binary version), although this will significantly increase CI time if we are exhaustive for 2.11, 2.12 & 2.13.

So my comment/suggestion is not related to this PR, but writing the recommendation on failure made me realize that having 2 different cases and actions makes it hard to use.

I am not familiar with the presentation compiler and how it's used in the rule to judge whether it's acceptable to ignore the patch release even for built-in rules, but since scalafix-cli is cross-built with a full version, I guess there was a reason?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion, we should relax this constraint.
I propose to support 3 scala versions of the compiler for each binary version of Scala, by the corresponding CI-tests.
It will increase ci-tests, but I think it's acceptable.

Copy link
Member

Choose a reason for hiding this comment

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

Just randomly jumping in here 😬, but quick question on the wording here. I actually just came across this while using https://github.com/joan38/mill-scalafix. I hit on this issue the message produced seems to be very sbt-specific while there is no guarantee that the user is using sbt here. I'm just curious if there is a better way to word this and avoid the setting key. I'm all for making error messages clear and actionable, but when the build tool is assumed, then it can get really confusing for someone not familiar with the ecosystem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey @ckipp01, thanks for the feedback and sorry for the late follow-up! You are right, this is very confusing, my proposal for this is #1199, let's follow-up there if you have any idea.

docs/rules/ExplicitResultTypes.md Show resolved Hide resolved
@bjaglin bjaglin marked this pull request as ready for review June 16, 2020 22:19
@bjaglin bjaglin requested review from olafurpg and mlachkar June 16, 2020 22:20
@mlachkar
Copy link
Collaborator

What do you think about merging this PR and I will finish/rebase this PR on top of it ?

@bjaglin
Copy link
Collaborator Author

bjaglin commented Jun 24, 2020

I was holding the merge mostly because of what was discussed in #1157 (and also to get @olafurpg's feedback), but I agree we can merge this and maybe aim at releasing 0.9.18 in the coming days (together will all other PRs and your follow-up) ? Go ahead and merge!

@bjaglin
Copy link
Collaborator Author

bjaglin commented Jul 1, 2020

I'll rebase this against #1174 once it's merged

@bjaglin bjaglin force-pushed the scalafixScalaBinaryVersion branch from c3a9eba to a085542 Compare July 2, 2020 12:11
@bjaglin
Copy link
Collaborator Author

bjaglin commented Jul 2, 2020

@mlachkar that's rebased!

@bjaglin bjaglin merged commit c5817c6 into scalacenter:master Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants