Build: Integrate Scalafix to auto-fix unused Scala imports#15676
Build: Integrate Scalafix to auto-fix unused Scala imports#15676jackylee-ch wants to merge 2 commits intoapache:mainfrom
Conversation
beaf75d to
b007c87
Compare
| For Scala code, unused imports are treated as compilation errors. To automatically remove unused imports, run [Scalafix](https://scalacenter.github.io/scalafix/): | ||
|
|
||
| ```bash | ||
| ./gradlew scalafix -DsparkVersions=4.0 -DscalaVersion=2.13 |
There was a problem hiding this comment.
Does this also work with Spark 3.5 scala 2.12?
|
LGTM from my side. Any other reviewers interested in taking a look? Maybe @RussellSpitzer ? |
|
I'm not familiar with this tool, I would just double check we can't already support this with the existing plugins we have. If not then I don't have a problem. I can review more seriously when I get to a computer since I'll need to learn more about this tool |
|
remind @RussellSpitzer, PTAL |
|
@jackylee-ch Did you have a response for my comment? |
Oh, sorry, I misunderstood. Just as I replied in the PR of Build: Apply spotless for scala code, there's currently no other solution to the unused import problem. |
|
|
||
| // When running scalafix, downgrade unused import errors to warnings so that | ||
| // compilation succeeds and SemanticDB is produced for Scalafix to process. | ||
| boolean scalafixRun = gradle.startParameter.taskNames.any { |
There was a problem hiding this comment.
This really feels like a bug in the cosmic-silence plugin. It should be automatically be downgrading the tasks on it's own.
There was a problem hiding this comment.
Its working principle is to handle the issue only after a Scala compile warning occurs, since it doesn't perform the unused check itself.
There was a problem hiding this comment.
In fact, introducing Scalafix is a bit heavy, but we lack this component.
Alternatively, do you think we can maintain the current state and let users handle this code style issue themselves when they receive compilation failures related to unused imports?
If so, the PR and the issue can be closed now.
There was a problem hiding this comment.
I think we are better off just not adding anything to the build, I've grown very paranoid of adding things to the build with all the supply chain attacks lately and even though I think this would be relatively safe, I don't think we really gain that much by giving folks an auto fix command. We aren't really a scala project so the benefits here feel very low compared to adding complexity to the build and a new plugin.
There was a problem hiding this comment.
OK, would close current PR and Issue. Thanks for your clarify.

Integrate Scalafix with the RemoveUnused rule to automatically fix unused Scala imports via
./gradlew scalafix.Fix #14342