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

When a comment has too many asterisks, phpcbf gives FAILED TO FIX error #1840

Closed
Flimm opened this issue Jan 5, 2018 · 1 comment
Closed
Milestone

Comments

@Flimm
Copy link

Flimm commented Jan 5, 2018

I have enabled Squiz.Commenting rule. Take this example file:

<?php
class Example {

	/** ************************************************************************
	 * Example
	 **************************************************************************/
	function example() {
	}
}

Running phpcs on this file gives several errors, the ones marked with [X] are:

 4 | ERROR | [x] Expected 5 space(s) before asterisk; 8 found
   |       |     (Squiz.Commenting.DocCommentAlignment.SpaceBeforeStar)
 4 | ERROR | [x] Expected 1 space after asterisk; 0 found
   |       |     (Squiz.Commenting.DocCommentAlignment.NoSpaceAfterStar)

So far, so good. However, running phpcbf gives this result:


PHPCBF RESULT SUMMARY
---------------------------------------------------------------------------------------------------------------
FILE            FIXED  REMAINING
---------------------------------------------------------------------------------------------------------------
...example.php  FAILED TO FIX
---------------------------------------------------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
---------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
---------------------------------------------------------------------------------------------------------------

Removing all the additional asterisks in the code fixes this problem. It would be nice if phpcbf knew how to handle this case.

Versions: PHPCS 3.2.2, PHP 7.1.12.

@gsherwood gsherwood changed the title When a comment has too many asterisks, phpcbf gives "FAILED TO FIX" error When a comment has too many asterisks, phpcbf gives FAILED TO FIX error Jan 11, 2018
gsherwood added a commit that referenced this issue Jan 11, 2018
@gsherwood
Copy link
Member

The problem here is that the opening line was being tokenized as an open tag, followed by whitespace, followed by an star, followed by a string (containing all stars). So then the sniff thought it should be checking the spacing before and after that star because it was the start of a docblock line. But in this case, it's not - it's just decoration.

I've changed the tokenizer so the first line is tokenized as an open tag, followed by whitespace, followed by a string (containing all stars). This stops the sniff from reporting any errors for the docblock in the example code.

There are currently no sniffs to either ban or enforce this style of commenting directly, but some sniffs may complain about the format indirectly and try to fix it up.

Thanks for reporting the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants