SONARJAVA-6525 Decrease FPs for the rule S117#5710
Conversation
…cal variable names Local variables inside methods may now use leading or trailing underscores (e.g. `_good`, `good_`, `__myVar__`); the core name between underscores is still validated against the configured format. The leniency does not apply to method parameters or fields. Test samples migrated to java-checks-test-sources. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…or parameters Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 1 resolved / 1 findingsUpdates S117 rule to allow leading and trailing underscores in local variable names, but fails to exclude constructor parameters from this leniency, causing incorrect validation logic. ✅ 1 resolved✅ Bug: Constructor parameters wrongly get underscore leniency
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|
francois-mora-sonarsource
left a comment
There was a problem hiding this comment.
There is a gap between the documented exception and the implementation. The RSPEC PR says the underscore leniency applies only to local variables declared inside a method body, and that method parameters are not affected. The current implementation instead strips leading/trailing underscores from any visited variable that is not a method or constructor parameter, which includes named lambda parameters such as _name -> _name. This makes lambda parameters compliant even though they are not covered by the documented exception. I do not think we need to assume here whether lambda parameters should or should not be exempt; either direction can be valid, but the implementation and documentation should make the same choice explicitly.




Local variables inside methods may now use leading or trailing underscores (e.g.
_good,good_,__myVar__), as a signal that the variable is temporary, unimportant, or intentionally unnamed.The core name between underscores is still validated against the configured format. The leniency does not apply to method parameters or fields.