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/BlockComment: fix fixer conflict and more #1717

Merged
merged 9 commits into from
Mar 9, 2018

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Oct 16, 2017

Came across this error when running fixer conflict checks for the various standards. (See #1645 (comment) )
Ninth fix in a series to fix the issues found.

To start with, this PR fixes a fixer conflict where the Squiz.Commenting.BlockComment sniff conflicts with itself.

To reproduce, run the following against the first commit (additional unit tests):
phpcbf -p -s ./src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc --standard=Squiz --sniffs=Squiz.Commenting.BlockComment.

The fixer conflict is caused by the sniff seeing the second block comment of the additional unit test as both:
a) an individual block comment and
b) as part of the first block comment, which leads to conflicting directives on what the indent should be.

Fixed by the second commit.

While working on this I noticed a number of other things which could use some love:

  1. The second block comment of the additional unit test was not recognized as an empty comment. This was caused by tabs for the indentation not being taken into account. Fixed in the third commit.
  2. For block comment lines which are prefixed with stars, the sniff would require too much indentation. (4 instead of 1). Fixed in the fourth commit.
  3. The sniff made a presumption that tab-width would always be 4. This would cause a fixer conflict with itself if tab-width was set to, for instance, 3. The fixer made the presumption that the expected indent would always be cleanly dividable by the tab-width and would end up continuously making the same fix as the indent used by the fixer would not be the same as the expected indent. Fixed in the fifth commit.
  4. And while I was at it, I noticed that the fixer for the LastLineIndent was missing while all other line indent error codes did have a fixer attached to it. Added in the sixth commit.

As a final commit I've made some minor efficiency fixes, reducing the number of (duplicate) function calls the sniff was making.


Updated

I've added one more commit to fix another fixer conflict.

To reproduce, run the following against master:
phpcbf -p -s ./src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc --standard=Squiz

Now the sniff will check whether a one-line /* */ comment is the last content on a line and only auto-fix it if it is. If not, it will throw an error, but won't auto-fix.


Updated (again)

I've added one more commit to fix a problem the sniff was having with the new PHPCS annotations.

See the commit message and the issue in which I reported the problem for more details.
I've (of course) added unit tests to demonstrate the issue and safeguard against it in the future.

For the builds to pass, I've had to rebase the PR to take advantage of fixes to the tokenizing of PHPCS annotations added between when this PR was originally pulled and now (PR #1901 and #1827).

Fixes #1918

@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 22, 2017

Rebased for merge conflicts & updated code style...

This fixes a fixer conflict when a second block comment is directly after a first.
If an empty comment was indented with tabs instead of spaces, it would not be recognized as empty.
Don't duplicate function calls already made.
This was causing fixer conflicts with other sniffs dealing with code whitespace rules.
@jrfnl jrfnl force-pushed the feature/fix-squiz-blockcomment branch from a1c96de to d99e8c6 Compare February 27, 2018 12:47
…ent closer to be misidentified.

Whether something was identified as a comment line was based on the token code being the same.
This did not allow for PHPCS annotations to be included in block comments as those have a different token code.

This resulted in comments being "cut short", i.e. the line above a PHPCS annotation being seen as the last line in a comment and subsequent comment lines being ignored, resulting in incorrect `Comment closer must be on a new line` and `Empty line required after block comment` notices.

Fixes 1918
@jrfnl jrfnl force-pushed the feature/fix-squiz-blockcomment branch 2 times, most recently from 37e5b0b to ce2b0fe Compare February 27, 2018 12:53
@gsherwood gsherwood merged commit ce2b0fe into squizlabs:master Mar 9, 2018
@gsherwood
Copy link
Member

Thanks a lot for all these fixes and improvements.

gsherwood added a commit that referenced this pull request Mar 9, 2018
@jrfnl jrfnl deleted the feature/fix-squiz-blockcomment branch March 9, 2018 07:14
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.

Squiz/BlockComment sniff: comment closer is misidentified when comment contains PHPCS annotation
2 participants