You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
PSR-2 includes requirement: "There MUST NOT be trailing whitespace at the end of non-blank lines.".
But in PSR-12 requirement changed to: "There MUST NOT be trailing whitespace at the end of lines.". Any line. Not only blank ones.
PHPCS seems to still use PSR-2 requirement, even if call it with PSR-12 standard.
Code sample (test.php)
<?php// some irrelevant codeecho"There are only two spaces in previous line";
// echo"There are two slashes and two spaces in previous line";
To reproduce
Steps to reproduce the behavior:
Create a file called test.php with the code sample above...
Run phpcs --standard=PSR12 -vvv test.php
See error message displayed
[...]
[PHP => 15 tokens in 7 lines]...
*** START TOKEN PROCESSING ***
Process token 0: T_OPEN_TAG => <?php\n
Processing PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\OpenTagSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\FileHeaderSniff... DONE in 0.0001 seconds
Processing PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff... DONE in 0.0001 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff... DONE in 0.0001 seconds
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff... DONE in 0.0002 seconds
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff... DONE in 0.0001 seconds
Process token 1: T_WHITESPACE => \n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 2: T_COMMENT => //·some·irrelevant·code\n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 3: T_WHITESPACE => ··\n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 4: T_ECHO => echo
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff... DONE in 0 seconds
Process token 5: T_WHITESPACE => ·
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 6: T_CONSTANT_ENCAPSED_STRING => "There·are·only·two·spaces·in·previous·line"
Process token 7: T_SEMICOLON => ;
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\DisallowMultipleStatementsSniff... DONE in 0 seconds
Process token 8: T_WHITESPACE => \n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 9: T_COMMENT => //··\n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0.0001 seconds
Process token 10: T_ECHO => echo
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff... DONE in 0 seconds
Process token 11: T_WHITESPACE => ·
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
Process token 12: T_CONSTANT_ENCAPSED_STRING => "There·are·two·slashes·and·two·spaces·in·previous·line"
Process token 13: T_SEMICOLON => ;
Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\DisallowMultipleStatementsSniff... DONE in 0 seconds
Process token 14: T_WHITESPACE => \n
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds
*** END TOKEN PROCESSING ***
[...]
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
6 | ERROR | [x] Whitespace found at end of line
----------------------------------------------------------------------
[...]
Expected behavior
In output summary, there should be another error indicated in the line 4 with the same (similar?) message: Whitespace found at end of line
Versions:
OS: Linux (Debian)
PHP: 5.6 and 7.2
PHPCS: 3.5.6
Standard: PSR12
Additional info
What is worth mentioning, using Squiz standard there's no such behaviour and line 4 is marked as "Whitespace found at end of line", so it's somehow possible. Tested on the same file with only changing standard to Squiz.
The text was updated successfully, but these errors were encountered:
It doesn't reference a reason for the change, besides the wording being confusing. That leads me to believe that the author believed they were keeping the intended message from PSR-2, but making the wording clearer. I have no idea if that's correct, but the commit does say "Trailing whitespace is not allowed in any situation", so I think that is clear enough to ban it on lines that only contain whitespace.
gsherwood
changed the title
PSR-12: incorrectly handle empty line with only whitespaces
PSR-12 not reporting error for empty lines with only whitespace
Sep 24, 2020
Describe the bug
PSR-2 includes requirement: "There MUST NOT be trailing whitespace at the end of non-blank lines.".
But in PSR-12 requirement changed to: "There MUST NOT be trailing whitespace at the end of lines.". Any line. Not only blank ones.
PHPCS seems to still use PSR-2 requirement, even if call it with PSR-12 standard.
Code sample (test.php)
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs --standard=PSR12 -vvv test.php
Expected behavior
In output summary, there should be another error indicated in the line 4 with the same (similar?) message: Whitespace found at end of line
Versions:
Additional info
What is worth mentioning, using Squiz standard there's no such behaviour and line 4 is marked as "Whitespace found at end of line", so it's somehow possible. Tested on the same file with only changing standard to Squiz.
The text was updated successfully, but these errors were encountered: