Skip to content

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

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

Closed
photodude opened this issue Sep 4, 2016 · 6 comments

Comments

@photodude
Copy link
Contributor

photodude commented Sep 4, 2016

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.

@gsherwood
Copy link
Member

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

@gsherwood
Copy link
Member

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

@gsherwood gsherwood changed the title File ending issue with Generic.Files.EndFileNewline and PSR2.Files.EndFileNewline Generic.Files.EndFileNewline and PSR2.Files.EndFileNewline don't detect newlines properly when the last token is a doc block Sep 7, 2016
@gsherwood gsherwood changed the title Generic.Files.EndFileNewline and PSR2.Files.EndFileNewline don't detect newlines properly when the last token is a doc block Sniffs that check EOF newlines don't detect newlines properly when the last token is a doc block Sep 7, 2016
gsherwood added a commit that referenced this issue Sep 7, 2016
…s properly when the last token is a doc block
gsherwood added a commit that referenced this issue Sep 7, 2016
…ould sometimes be (boolean) false (was causing failures for #1141)
@photodude
Copy link
Contributor Author

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.

@gsherwood
Copy link
Member

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.

@gsherwood
Copy link
Member

Forgot to say: thanks for the bug report :)

@photodude
Copy link
Contributor Author

You are welcome, Thank you.

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