PSR2/SwitchDeclaration: various bug fixes #3354
Merged
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.
PSR2/SwitchDeclaration: bug fix - don't remove trailing comments
As reported in #3352, the
PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE
fixer could inadvertently remove trailing comments.This commit improves on the fix which was put in place in response to #683, by making the detection of what should be considered the start of the body more precise:
case
will be ignored.T_COMMENT
tokens.case
and non-empty tokens on the same line as thecase
will both be considered as the "start of the body".As for the fixer. The "body starts on same line" fixer was already okay. The "empty lines between case and body" fixer, however, will now ignore anything on the same line as the
case
, which prevents us having to account for comments which already include a new line.Includes unit tests.
Fixes #3352
PSR2/SwitchDeclaration: bug fix - improve handling of comments
Comments in certain places in the code flow would throw the
findNestedTerminator()
method used for determining theTerminatingComment
error off.Fixed now.
Includes unit tests.
Without this fix, the first test would not throw an error (false negative), while the second would (false positive).
PSR2/SwitchDeclaration: minor efficiency tweak
PSR2/SwitchDeclaration: bug fix - handle try/catch/finally correctly
Add code to handle
try-catch-finally
statements correctly when determining whether acase
needs a terminating comment.As per #3297 (comment):
Includes plenty of unit tests.
Fixes #3297