scalafix icon indicating copy to clipboard operation
scalafix copied to clipboard

RemoveUnused does not clean up nested unused references

Open gatisnolv opened this issue 4 years ago • 1 comments
trafficstars

Consider this example:

class Example {
    private def a = 1
    private def b = a
    private def c = b
}

To clean it up from all the unused references requires 3 separate invocations of scalafix. I suppose that's because the compiler only reports one of them as unused per invocation. I think it would make sense that these would be picked up in a single scalafix invocation. I'm not sure what would be the best approach to address this as I'm new to scalafix and ran into this while cleaning up a project.

gatisnolv avatar Aug 17 '21 13:08 gatisnolv

Thanks for the report/suggestion! The best would be to get compiler support (maybe there is already a ticket about that?), as working around this limitation in Scalafix is possible but not trivial. It's somewhat similar to https://github.com/scalacenter/scalafix/issues/1204 (on which there is no active work ongoing). The compiler needs to be re-run several times, ideally from scalafix itself (provided that an API for the client to pass a hook to trigger the compiler is added) or from sbt-scalafix (in which case a new command seems to be the best way, as a task can only safely call another task once). In any case, this cannot be the default as not all rules are guaranteed to converge to a stable state (or even meant to be run twice).

bjaglin avatar Aug 22 '21 19:08 bjaglin