Php_codesniffer: Sniffs that check EOF newlines don't detect newlines properly when the last token is a doc block

Created on 5 Sep 2016  路  6Comments  路  Source: squizlabs/PHP_CodeSniffer

I have run into occasions where Generic.Files.EndFileNewline or PSR2.Files.EndFileNewline will throw an error on a file that does end with a new line.

Fixing the files with phpcbf will add another new line and will still error when checked again. this is what a post fixer error looks like

 13 | ERROR | [x] File must end with a newline character (Generic.Files.EndFileNewline.NotFound)
 13 | ERROR | [x] Additional blank lines found at end of doc comment (Generic.Commenting.DocComment.SpacingAfter)

Example files that have such an issue are included (one PHP, one CSS).

GitHub.zip

Expected behavior

If there is an empty new line at the end of the file there should be no PSR2.Files.EndFileNewline.NoneFound or Generic.Files.EndFileNewline.NoneFound error Expected 1 newline at end of file; 0 found regardless of the code that is before that last newline in the file.

Bug

Most helpful comment

Just confirming this is fixed now. Had a few unit test problems given the comment was not closed. Especially with HHVM, which just removed that entire comment from the file content while parsing.

All 6 comments

This is because the last token is a doc comment, and is tokenized as T_DOC_COMMENT_WHITESPACE. Should hopefully be an easy fix.

Note that your second file doesn't produce any errors.

I should note that the first file is a snippet from a larger file that would error out. https://raw.githubusercontent.com/Kunena/Kunena-Forum/K5.1/src/libraries/kunena/bbcode/bbcode.php

As for the second file, it was erroring on 2.6.0 so maybe it's no longer an issue in 2.7.0.

Just confirming this is fixed now. Had a few unit test problems given the comment was not closed. Especially with HHVM, which just removed that entire comment from the file content while parsing.

Forgot to say: thanks for the bug report :)

You are welcome, Thank you.

Was this page helpful?
0 / 5 - 0 ratings