Repository navigation
[java] Fix #6846: VariableDeclarationUsageDistance: False positive with variables grouped at the top of a block - #6860
Merged
UncleOwen merged 5 commits intoJul 25, 2026
Conversation
… with variables grouped at top of block
onetuks
force-pushed
the
fix/6846-variable-declaration-usage-distance
branch
from
July 10, 2026 04:00
92309f8 to
a939a03
Compare
Member
|
See my comment in #6846. Let's first discuss what needs changing (if anything), then do the implementation. |
UncleOwen
requested changes
Jul 10, 2026
…itive with variables grouped (doesn't count consecutive local variable declarations)
UncleOwen
requested changes
Jul 16, 2026
Contributor
Author
|
@UncleOwen |
…ion distance count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the PR
VariableDeclarationUsageDistancecurrently counts every statement between a localvariable's declaration and its first usage, including other unrelated variable
declarations. This produces a false positive for a common coding style where all
local variables are declared together at the very top of a block (e.g. alphabetized),
before any executable code:
This PR adds a new opt-in property ignoreVariablesAtTopOfBlock (default: false).
When enabled, a variable is exempted from the distance check if it is declared
together with at least one other variable at the very top of its enclosing block,
before any other statement.
The property is opt-in rather than a change to the default behavior, because an
existing test case (int sum = 0; int unused = 0; ...) intentionally expects a
variable in the same "grouped declaration" position to still be flagged. Changing
the default would silently suppress violations for existing users, so this is
left as an explicit choice.
Related issues
Fix #6846
Ready?