Allow local variable names that start with underscore#3422
Allow local variable names that start with underscore#3422
Conversation
Generate changelog in
|
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
|
👎 from me. There's no reason to declare a variable that is unused. If the goal is to silence the I don't really agree with the |
Before this PR
For code with an unused local variable name like this:
There's an error prone rule StrictUnusedVariable that fires with a message like
But then if you take the suggestion and name the variable according to its suggestion like this:
Then now checkstyle fails with an error like:
It is problematic that the baseline error prone suggests a format that then the baseline checkstyle configuration rejects.
After this PR
==COMMIT_MSG==
Allow local variable names that start with underscore
==COMMIT_MSG==
With this PR, now the recommendation from StrictUnusedVariable can actually be taken.
The regex is similar to the existing regex ~15 lines below for
ParameterNameAlternative: no variable assignment
Instead of make this allowed in checkstyle, an alternative could be to stop recommending it in error-prone. Now users should resolve the original error by removing the variable assignment entirely, like this:
However, this interacts poorly with the FutureReturnValueIgnored bug pattern, which would now fail with this message:
and is recommending to create an unused variable assignment again!
For users truly trying to fire and forget a future, they would have to suppress the error-prone at the surrounding method. Unfortunately this is a very wide suppression and can suppress over hundreds of lines when the problem is only in one. Like this:
Because of this bad interaction with
FutureReturnValueIgnored, I think it's better to move towards an explicit assignment to an unused variable that starts with an underscore.In the end, making this the desirable and allowed phrasing:
and allowing the
_prefix for variable names in checkstyle (what this PR does)