scalacenter / scalafix

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

Run scalafix on compile #584

Closed OlegYch closed 6 years ago

OlegYch commented 6 years ago

the linting should work the same way scalac/wartremover linting works (at least optionally), ie on each compilation it should check modified files

olafurpg commented 6 years ago

The best way to approach this would be to implement a compiler plugin that uses the scalafix library API. Then scalafix would report errors just like wartremover and run incrementally only on modified files. We'd need to take care of how this compiler plugin interacts with semanticdb-scalac, which scalafix currently requires.

I probably won't be working on this personally in the near future. If someone is interested in contributing in this space I can try to give some pointers, but I estimate it will require a bit of work.

I personally believe the best way to consume scalafix linter/refactoring suggestions will be through an editor. This would allow you to optionally apply auto-fixes. We already have proof-of-concept LSP integration in https://github.com/scalameta/metals

olafurpg commented 6 years ago

This is a great idea but I am afraid it is not on the near roadmap. Scalafix on compile would require a different integration than the current sbt plugin and command-line interface: a compiler plugin. The tricky part is to make sure the compiler plugin plays nicely with the existing semanticdb-scalac compiler plugin. Implementation wise it should not be difficult otherwise.

Please reopen if you are interested in working on this and taking on responsibility to maintain the compiler plugin. I suspect many will enjoy using this feature. Beware however, linting on compile is challenging since

  1. it's on a critical path blocking compilation
  2. there is no tolerance for false positives, linter rules that run on compile must be extra high quality

If you want linting on compile today I recommend using wartremover. It's a great project with a range of builtin rules and support for writing custom rules http://www.wartremover.org/