scalacenter / scalafix

Refactoring and linting tool for Scala
https://scalacenter.github.io/scalafix/
BSD 3-Clause "New" or "Revised" License
830 stars 186 forks source link

SBT scalafix does not work #38

Closed dario01 closed 7 years ago

dario01 commented 7 years ago

With the following steps the sbt-test fails for me, not sure what I am doing wrong?

Output:

[error] p1/src/test/scala/Test.scala [error] File: p1/src/test/scala/Test.scala [error] Obtained output: [error] object TestMain { [error] implicit val x = 2 [error] lazy val y = 2 [error] def main(args: Array[String]) { [error] println("hello") [error] } [error] } [error] Expected: [error] object TestMain { [error] implicit val x: Int = 2 [error] lazy val y = 2 [error] def main(args: Array[String]): Unit = { [error] println("hello") [error] } [error] } ...

olafurpg commented 7 years ago

Thank you for reporting! I am able to reproduce on the 0.2.1 release but not on master branch. I added several new tests in #39 while trying to track down the issue but still no luck. Weird, maybe I botchered the 0.2.1 release. I just published 0.2.2-RC1 to see if the release process is the culprit.

olafurpg commented 7 years ago

I am not able to reproduce the issue on 0.2.2-RC1. If you can confirm this is also the case for you, then I will go ahead and publish it as 0.2.2.

dario01 commented 7 years ago

I can still reproduce the issue in 0.2.2-RC1 as follows:

olafurpg commented 7 years ago

This is weird, I can reproduce the error on a clean ivy cache but not after I've published the library locally. That explains why CI is green but the sbt plugin still doesn't work. The biggest surprise to me is that the scalafix command exists silently without errors, I wonder what could be happening.

It's been a real challenge to cross-build the core to 2.11/12 while keeping the sbt plugin 2.10 only.

dario01 commented 7 years ago

It may have to do with the jar being published for 2.11 instead of 2.10.

Mine is for example published here: ~/.ivy2/local/ch.epfl.scala/scalafix-nsc_2.11/0.2.1/jars/scalafix-nsc_2.11.jar

olafurpg commented 7 years ago

Can you try with 0.2.0-RC3? I am now unable to reproduce the problem on a machine with empty ivy cache. The problem appears to be that publishLocal produces jars with name VERSION/scalafix-nsc_2.11.jar while the jars that get published to maven are named scalafix-nsc_2.11-VERSION.jar. The sbt plugin needs to extract the jar absolute path to correctly set -Xplugin:/.../scalafix-nsc.jar.

dario01 commented 7 years ago

I tried with 0.2.2-RC3 (not 0.2.0-RC3) and it all works great.

Yes, I had added earlier the -Xplugin: setting manually during sbt session to unblock myself.

Note that in addition to sbt publishLocal there is also sbt publishM2, perhaps it helps debugging these kind of issues in the future.

Would it be simpler if as part of the sbt setup instructions we also had: libraryDependencies += "ch.epfl.scala" %% "scalafix-nsc" % scalafixVersion

olafurpg commented 7 years ago

Awesome! Yes, good catch, I meant 0.2.2-RC3.

Would it be simpler if as part of the sbt setup instructions we also had: libraryDependencies += "ch.epfl.scala" %% "scalafix-nsc" % scalafixVersion

That wouldn't necessarily help since scalafix-nsc is a compiler plugin, which are treated by sbt in a special way. I tried addCompilerPlugin but that did not work for some reason. The current setup is modeled after scoverage, but I deviated a bit on how to handle the jar extraction (which was the cause of this bug). I hope we won't hit on more related issues : )

I'll go ahead and publish 0.2.2 then!