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

Remove -Xfatal-warnings scalac option in scalafixEnable #1346

Closed
fthomas opened this issue Mar 2, 2021 · 3 comments · Fixed by scalacenter/sbt-scalafix#195
Closed

Remove -Xfatal-warnings scalac option in scalafixEnable #1346

fthomas opened this issue Mar 2, 2021 · 3 comments · Fixed by scalacenter/sbt-scalafix#195

Comments

@fthomas
Copy link
Contributor

fthomas commented Mar 2, 2021

-Xfatal-warnings (or -Werror) might prevent a Scalafix rule from being applied if a project does not compile without warnings with the Scala version set by scalafixEnable. I noticed this while testing a Scalafix migration rule for Cats Effect (scala-steward-org/scala-steward#1982) in Scala Steward itself. Scala Steward uses -Xfatal-warnings and sbt-scalafix 0.9.26 but is still on Scala 2.13.4. I tested the migration rule via sbt ;scalafixEnable ;scalafix github:typelevel/cats-effect/v2_4_0?sha=series/2.x and noticed that it couldn't be applied because compilation fails under Scala 2.13.5 which introduced new warnings. Scala 2.13.5 is used instead of 2.13.4 because scalafixEnable also changes the scalaVersion. If I remove -Xfatal-warnings from scalacOptions in the build, compilation succeeds and the Scalafix rule is applied.

This is not really an issue if one runs the Scalafix manually (since one can always remove that option by hand) but it is more problematic when Scalafix is used in automation. One example is when Scala Steward runs Scalafix migration rules in other projects as part of its update PRs. It currently does this by adding the latest sbt-scalafix version to the build of the project it is updating and then running sbt ;scalafixEnable ;scalafix .... If that project is using -Xfatal-warnings it could run into the situation mentioned above which prevents the Scalafix rule from being applied.

I tried to salvage this in Scala Steward by adding another sbt command that is executed after scalafixEnable which removes -Xfatal-warnings from all sbt projects but this is unfortunately not possible due to bug in sbt: sbt/sbt#5459. I therefore propose that scalafixEnable also removes -Xfatal-warnings and -Werror from scalacOptions to make using sbt-scalafix easier in projects where the actual scalaVersion and the one set by scalafixEnable differ.

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 3, 2021

As discussed on gitter, I think it's a good idea. I was concerned about relaxing -Xfatal-warnings for the entire session after scalafixEnable, but I think I got something decent with scalacenter/sbt-scalafix#195. Could you confirm this PR addresses your use case?

@fthomas
Copy link
Contributor Author

fthomas commented Mar 4, 2021

Just tested it and it works like a charm. Thank you @bjaglin!

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 24, 2022

@fthomas scalacenter/sbt-scalafix#292 should benefit steward by avoiding some of the challenges described above, your feedback is welcome.

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 a pull request may close this issue.

2 participants