-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused terms #238
Comments
I like this! We could also have an "aggressive" option that removes them indiscriminately, for users that are confident no side-effects happen on the rhs. |
That should be doable. Note that this rewrite will need to provide some escape hatch for cases like this in the scalafix codebase [warn] <macro>:3: private val FilterMatcherReader in class PrintStreamReporter is never used
[warn] private val FilterMatcherReader = null
[warn] ^
[warn] one warning found That statement is necessary to shadow another implicit, removing the line will cause a compilation error. What would be a sane escape hatch? private val FilterMatcherReader = null // scalafix: ignore
private val FilterMatcherReader = null // This line is necessary because ... |
Ugh, I didn't know you could do something like that :D In that specific case, why isn't Anyway, a general |
+1 to scalafix: ignore. It follows the style of wartRemover suppressWarnings, scalafmt ignore, scalastyle ignore, etc. All of these tools end up needing an escape hatch sooner or later, ignore seems like the popular way to do it. Just two weeks ago I tried to run scalafix on sbt codebase and ended up wanting to ignore a bunch of generated files that were in source with a //Do not modify by hand comment on them. |
@ShaneDelmore do you think the escape hatch message should be configurable? In order to accommodate code generated code like you mention. Implementing the actual escape hatch should not be too difficult, I believe nailing the interface is harder. |
I don’t understand the question about configuring the escape hatch message, do you mean a message scalafix provides, or the comment to trigger skipping a rewrite? If you mean various levels of escaping, I think that makes sense. That covers all of the cases I can think of right now. |
That's exactly what I was looking for @ShaneDelmore Thank you. I agree it would be nice to have fine-grained control over how to disable scalafix. I think it's possible to let comments at the end of statements disable the whole statement
|
I opened #241 to track the escape hatch |
#238 Rule to remove unused local val and var
Fixed in #367 |
scalac can report warnings on unused terms like this
it would be nice if scalafix could automatically remove those definitions. Note that the right-hand side of the definition may contain side-effects so we can't remove those unless they are 100% side-effect free (for example literals)
The text was updated successfully, but these errors were encountered: