scalafix
scalafix copied to clipboard
Ability to rename and create files
I'd love to write two scalafix rules:
- split scala files with multiple top-level types in to one file per type. (eg.
lib.scala
=>Hi.scala
andOk.scala
) - move files so that their path matches the package (i.e. Java style)
I don't see any functionality that I could use to rename or create files. I was looking through all of the Patch
methods and there was nothing there. Is there some other means to accomplish this?
Indeed, there is nothing built-in in Scalafix for that. I am not aware of any previous (public) discussion either.
(2) could easily be implemented by an addition to the Patch
API.
(1) would require much more thinking. Spontaneously, I feel like a Fork/Copy patch could be the easiest to implement and reason about (in terms of patch composeability and avoiding generating broken source because of missing imports). This patch could itself embed other patches to be applied on the forked file to allow further processing.
Hi again,
So for now, I've made my own app called scala-restructure that does what I need it to do, but directly using scalameta, rather that trying to use scalafix and the Patch API. It works well and is a great alternative (especially considering that scalafix is OSS) but if anyone has the time and inclination, it would be awesome to find a way to integrate that work into scalafix so that these could be normal scalafix rules.
Anyway, I hope that's helpful. Thanks!