Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz/Functionspacing: fix fixer conflict + a fixer bug #2277

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 30, 2018

[Fixer conflicts series PR]

Fixer conflict can be reproduced by running the below command against master:
phpcbf -p -s ./src/Standards/Squiz/Tests/WhiteSpace/FunctionOpeningBraceSpaceUnitTest.inc --standard=Squiz

Introduced by me via #2110, which was included in the 3.3.2 release, and didn't take global functions straight after a PHP open tag into account. Mea Culpa.

Basically, when a function is on the first line after a PHP open tag at the start of the file, the whitespace would be added before the open tag, not before the function.
This in turn causes a conflict with the SuperfluousWhiteSpace sniff which will try to remove whitespace before the open tag at the start of file.

While adding unit tests for this, I also discovered a second, more serious bug, where, when there were too many blank lines between a PHP open tag at the start of a file and the first function, the PHP open tag would be removed altogether, which would cause the file to be regarded as inline HTML.

These situations were not covered by unit tests yet and all need separate files to be tested properly. These tests have now been added to prevent this issue from reoccurring in the future.

Additionally, I've added:

  • A unit test documenting how the sniff handles blank lines around functions when the function is not on its own line.
  • Unit tests documenting that the sniff also handles functions in traits and anonymous classes correctly.
  • Some minor other code simplifications and documentation improvements.

[Fixer conflicts series PR]

Fixer conflict can be reproduced by running the below command against master:
phpcbf -p -s ./src/Standards/Squiz/Tests/WhiteSpace/FunctionOpeningBraceSpaceUnitTest.inc --standard=Squiz

Introduced by me via 2110, which was included in the 3.3.2 release, and didn't take global functions straight after a PHP open tag into account. Mea Culpa.

Basically, when a function is on the first line after a PHP open tag at the start of the file, the whitespace would be added before the open tag, not before the function.
This in turn causes a conflict with the `SuperfluousWhiteSpace` sniff which will try to remove whitespace before the open tag at the start of file.

While adding unit tests for this, I also discovered a second, more serious bug, where, when there were too _many_ blank lines between a PHP open tag at the start of a file and the first function, the PHP open tag would be removed altogether, which would cause the file to be regarded as inline HTML.

These situations were not covered by unit tests yet and all need separate files to be tested properly. These tests have now been added to prevent this issue from reoccuring in the future.
…ion line

Add unit test documenting how the sniff handles blank lines around functions when the function is not on its own line.
Add unit tests documenting that the sniff also handles functions in traits and anonymous classes correctly.
Minor other code simplifications and documentation improvements.
@jrfnl jrfnl force-pushed the feature/squiz-functionspacing-fix-fixer-conflict branch from 17a7a8c to 35c32fe Compare January 8, 2019 03:17
@jrfnl
Copy link
Contributor Author

jrfnl commented Jan 8, 2019

Rebased to get past imaginary merge conflict.

@gsherwood gsherwood merged commit 35c32fe into squizlabs:master Jan 17, 2019
gsherwood added a commit that referenced this pull request Jan 17, 2019
@gsherwood
Copy link
Member

Thanks

@jrfnl jrfnl deleted the feature/squiz-functionspacing-fix-fixer-conflict branch January 17, 2019 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants