Squiz/MemberVarSpacing: bug fix / improve parse error handling #832
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.
Description
Squiz/MemberVarSpacing: rename test case file
... to allow for adding additional test case files for code containing parse errors.
Squiz/MemberVarSpacing: bug fix / improve parse error handling
The
Squiz.WhiteSpace.MemberVarSpacing
sniff checks the number of blank lines before a property declaration.To determine the number of blank lines before a property, it tries to find the start of the statement by:
Only after all that it checks the number of blank lines.
The first step however leads to problems when, during live coding, a property would be declared without a modifier keyword.
In that case, the sniff could walk back much further than it should, potentially misidentifying a modifier keyword for a function for the modifier keyword for the property.
While this is an edge-case as it is not customary for properties to be declared after functions, the sniff should still handle this situation correctly.
Fixed by changing the logic of the sniff to stop searching earlier.
Includes new test case files, both of which demonstrate the bug.
Additionally, the test in the
1
file safeguards that the current behaviour of the sniff for multi-property declarations is not aversely affected by the fix.Suggested changelog entry
Squiz.WhiteSpace.MemberVarSpacing: prevent potential fixer conflict during live coding
Related issues/external references
Note: this PR is part of a series of PRs to fix various issues in this sniff...
Related to #152
Types of changes