Variables prefixed with `unused` shouldn't trigger a "never used" warning
kluever opened this issue · 2 comments
Background: As part of our larger effort to expand the scope of CheckReturnValue
, we'll be spraying var unused =
around our codebase to capture the result of function calls to APIs that are marked with @CheckReturnValue
.
In Java, ErrorProne has a checker that warns when a variable is declared but not used (very similar to kotlinc). However, the checker has an important carve out: it doesn't issue a warning for variables prefixed with unused
.
This scenario also comes up if you're implementing an interface, and forced to implement a function but you don't need to use one of the function parameters. You can avoid the warning by simply naming the function parameter unusedFoo
.
I propose updating kotlinc to avoid issuing such a warning if the variable name is prefixed with unused
:
java/com/foo/bar/MessageExtensions.kt:11:7: warning: variable 'unused' is never used
(As the person who added this to Error Prone) My rationale is: since the variable name shows clearly that the user is already aware, imho it makes sense to not warn.
Even better: renaming or prefixing with "unused" is a superior alternative to suppression, because if the variable does get used, something will look quite wrong until the variable gets renamed, which is just what you want.
There is the issue that some variables are intentionally named "unused*". I think it is a very small problem.