Skip to content

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Mar 15, 2018

As discussed in #1931, moving a trailing phpcs:ignore annotation to the next line changes its meaning, which is what currently happens when the ContentAfterBrace error is triggered by one of the new PHPCS annotations in the Generic.Functions.OpeningFunctionBraceKernighanRitchie and Generic.Functions.OpeningFunctionBraceBsdAllman sniffs.

For the Generic.Functions.OpeningFunctionBraceBsdAllman sniff, this also impacts the fixer of the BraceOnSameLine errror which could also move the comment down.

This PR fixes that.

For this fix, I've chosen to ignore all the PHPCS annotations, not just the phpcs:ignore one. If so desired, I can change the PR to only make an exception for a trailing phpcs:ignore comment and to move phpcs:disable/enable/set comments to the next line, just like "normal" comments.

Includes unit tests.

…ations

As discussed in 1931, moving a trailing `phpcs:ignore` annotation to the next line changes its meaning, which is what currently happens when the `ContentAfterBrace` error is triggered by one of the new PHPCS annotations in the `Generic.Functions.OpeningFunctionBraceKernighanRitchie` and `Generic.Functions.OpeningFunctionBraceBsdAllman` sniffs.

For the `Generic.Functions.OpeningFunctionBraceBsdAllman` sniff, this also impacts the fixer of the `BraceOnSameLine` errror which could also move the comment down.

This PR fixes that.

For this fix, I've chosen to ignore *all* the PHPCS annotations, not just the `phpcs:ignore` one. If so desired, I can change the PR to only make an exception for a trailing `phpcs:ignore` comment and to move `phpcs:disable/enable/set` comments to the next line, just like "normal" comments.

Includes unit tests.
@gsherwood gsherwood changed the title Generic/OpeningBrace sniffs: fix bug in fixer handling of PHPCS annotations Generic opening brace placement sniffs incorrectly move PHPCS annotations Mar 15, 2018
@gsherwood gsherwood added this to the 3.3.0 milestone Mar 15, 2018
@gsherwood gsherwood merged commit bfeffa3 into squizlabs:master Mar 15, 2018
gsherwood added a commit that referenced this pull request Mar 15, 2018
gsherwood added a commit that referenced this pull request Mar 15, 2018
@gsherwood
Copy link
Member

For this fix, I've chosen to ignore all the PHPCS annotations

I think that makes sense. Thanks a lot for fixing this.

@jrfnl jrfnl deleted the feature/generic-opening-brace-phpcs-annotations branch March 16, 2018 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants