FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19928&edit=1

ID: 19928
Updated by: boonedox@gmail.com
Reported By: boonedox@gmail.com
-Summary: bug in newline stana
+Summary: bug in newline standard
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Gentoo
Package Version: 1.4.5
PHP Version: 5.4.6
Roadmap Versions:
New Comment:

-Summary: bug in newline stana
+Summary: bug in newline standard



Previous Comments:
------------------------------------------------------------------------

[2013-05-02 00:03:36] boonedox

Description:
------------
PSR2_Sniffs_Files_EndFileNewlineSniff::process is incorrectly
checking blank lines at the end of the file. It is reporting an
error
when $blankLines > 0, which is incorrect, because $blankLines
should be 1. This is also a check that is done by
PSR2_Sniffs_Files_EndFileWhitespaceSniff. I believe the
blankLines check is supposed to be in
PSR2_Sniffs_Files_EndFileWhitespaceSniff while
PSR2_Sniffs_Files_EndFileNewlineSniff should just be checking
that the file ends w/ a
unix line ending.

old code in PSR2_Sniffs_Files_EndFileNewlineSniff::process
if ($blankLines === 0) {
$error = 'Expected 1 blank line at end of file; 0
found';
$data = array($blankLines);
$phpcsFile->addError($error, $stackPtr, 'NotFound',
$data);
} else if ($blankLines > 1) {
$error = 'Expected 1 blank line at end of file; "%s"
found';
$data = array($blankLines);
$phpcsFile->addError($error, $stackPtr, 'TooMany',
$data);
}

new code in 1.4.5 for
PSR2_Sniffs_Files_EndFileNewlineSniff::process
if ($blankLines > 0) {
$error = 'Expected 1 blank line at end of file; %s
found';
$data = array($blankLines + 1);
$phpcsFile->addError($error, $stackPtr, 'TooMany',
$data);
}


Test script:
---------------
phpcs --standard=PSR2 world.php

Expected result:
----------------
Time: 0 seconds, Memory: 4.75Mb

Actual result:
--------------
FILE: /world.php
------------------------------------------------------------------------
--------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
------------------------------------------------------------------------
--------
11 | ERROR | Expected 1 blank line at end of file; 2 found
------------------------------------------------------------------------
--------

Time: 0 seconds, Memory: 4.75Mb

------------------------------------------------------------------------

Search Discussions

  • Gsherwood at May 1, 2013 at 10:48 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19928&edit=1

    ID: 19928
    Updated by: gsherwood@squiz.net
    Reported By: boonedox@gmail.com
    Summary: bug in newline standard
    -Status: Open
    +Status: Bogus
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Gentoo
    Package Version: 1.4.5
    PHP Version: 5.4.6
    -Assigned To:
    +Assigned To: squiz
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Bogus
    -Assigned To:
    +Assigned To: squiz
    First, the part of the standard that this sniff is checking is: "All PHP
    files MUST end
    with a single blank line."

    So it has to check that files end with a newline and also that there is
    a single blank
    line at the end. It's the same part of the standard, so it goes in the
    same sniff.

    There was a long discussed on the PHP-FIG mailing list about what this
    meant:
    https://groups.google.com/forum/?fromgroups=#!topic/php-
    fig/PSzmcFVQst0%5B1-25-false%5D

    Summary was: there should be 2 newline characters at the end of a file.
    So I
    coded it like that, checking for the single blank line, as per the old
    cold you posted.

    But this was questioned again later on and the decision was corrected by
    PHP-FIG.
    It turns out there was only ever supposed to be 1 newline at the end of
    the file and
    the blank line you see is only visible in some text editors (like ST2).
    Unfortunately,
    I can't find the link to that discussion.

    So I corrected the sniff:
    https://github.com/squizlabs/PHP_CodeSniffer/commit/13de87f031b1bb6f15255f0c
    4f99f9e600724855

    Hope that clears up why the code was changed. PHP-FIG just changed their
    mind.
    Unit tests were updated accordingly.


    Previous Comments:
    ------------------------------------------------------------------------

    [2013-05-02 00:05:45] boonedox

    -Summary: bug in newline stana
    +Summary: bug in newline standard


    ------------------------------------------------------------------------

    [2013-05-02 00:03:36] boonedox

    Description:
    ------------
    PSR2_Sniffs_Files_EndFileNewlineSniff::process is incorrectly
    checking blank lines at the end of the file. It is reporting an
    error
    when $blankLines > 0, which is incorrect, because $blankLines
    should be 1. This is also a check that is done by
    PSR2_Sniffs_Files_EndFileWhitespaceSniff. I believe the
    blankLines check is supposed to be in
    PSR2_Sniffs_Files_EndFileWhitespaceSniff while
    PSR2_Sniffs_Files_EndFileNewlineSniff should just be checking
    that the file ends w/ a
    unix line ending.

    old code in PSR2_Sniffs_Files_EndFileNewlineSniff::process
    if ($blankLines === 0) {
    $error = 'Expected 1 blank line at end of file; 0
    found';
    $data = array($blankLines);
    $phpcsFile->addError($error, $stackPtr, 'NotFound',
    $data);
    } else if ($blankLines > 1) {
    $error = 'Expected 1 blank line at end of file; "%s"
    found';
    $data = array($blankLines);
    $phpcsFile->addError($error, $stackPtr, 'TooMany',
    $data);
    }

    new code in 1.4.5 for
    PSR2_Sniffs_Files_EndFileNewlineSniff::process
    if ($blankLines > 0) {
    $error = 'Expected 1 blank line at end of file; %s
    found';
    $data = array($blankLines + 1);
    $phpcsFile->addError($error, $stackPtr, 'TooMany',
    $data);
    }


    Test script:
    ---------------
    phpcs --standard=PSR2 world.php

    Expected result:
    ----------------
    Time: 0 seconds, Memory: 4.75Mb

    Actual result:
    --------------
    FILE: /world.php
    ------------------------------------------------------------------------
    --------
    FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
    ------------------------------------------------------------------------
    --------
    11 | ERROR | Expected 1 blank line at end of file; 2 found
    ------------------------------------------------------------------------
    --------

    Time: 0 seconds, Memory: 4.75Mb

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedMay 1, '13 at 10:03p
activeMay 1, '13 at 10:48p
posts2
users2
websitepear.php.net

2 users in discussion

Boonedox: 1 post Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase