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

ID: 19437
Comment by: juanmf
Reported By: juanmf@gmail.com
Summary: Ingoring Sniffs with dots on Windows
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Windows 7, 64-bit
Package Version: 1.3.4
PHP Version: 5.3.13
New Comment:

$sniffPos = strrpos($file,
DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
false === $sniffPos && $sniffPos = strrpos($file,
'/Sniffs/');

added the 2nd line. at line 660. made it work.


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

[2012-05-24 17:12:01] jakubboucek

Description:
------------
If i use some rules with dots in name like a
<rule ref="Generic.Files.LineLength">
then will be library path defined as
\pear\PHP\CodeSniffer/Standards/Generic/Sniffs/Files\LineLengthSniff.php

See the shlashes - some is right-shlash, other is backshlash.

While running test, this rule is ignored.

Why? Function setTokenListeners() tests, if the sniff's path is in the
right conventions and check it with DIRECTORY_SEPARATOR. Specifically
check if the string contains '\Sniffs\'. As I said, this part of string
is directly defined with / (right-slash). Test fails and Sniff
definition is ignored.

The simpliest fix is appending the line above path checking:
//File: <pear_root>\PHP\CodeSniffer.php:656
//Notmalize path
$file = realpath($file);

Test script:
---------------
ruleset.xml

<?xml version="1.0"?>
<ruleset name="Bug check">
<rule ref="Generic.Commenting.Todo" />
</ruleset>


Expected result:
----------------
Registering sniffs in Bug check standard... DONE (1 sniffs registered)

Actual result:
--------------
Registering sniffs in Bug check standard... DONE (0 sniffs registered)

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

Search Discussions

  • Gsherwood at Jun 18, 2012 at 11:11 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19437&edit=1

    ID: 19437
    Updated by: gsherwood@squiz.net
    Reported By: jakub dot boucek@socialbakers.com
    Summary: Ingoring Sniffs with dots on Windows
    -Status: Open
    +Status: Feedback
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Windows 7, 64-bit
    Package Version: 1.3.4
    PHP Version: 5.3.13
    -Assigned To:
    +Assigned To: squiz
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Feedback
    -Assigned To:
    +Assigned To: squiz
    I think this is the same as bug #19471, which I committed a fix for. Can
    you please
    try the latest git version of PHPCS to see if this resolves the issue.

    Instructions for running from a git clone are here:
    https://github.com/squizlabs/PHP_CodeSniffer/blob/master/README.markdown#insta
    llation


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

    [2012-06-05 02:33:04] juanmf

    $sniffPos = strrpos($file,
    DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
    false === $sniffPos && $sniffPos = strrpos($file,
    '/Sniffs/');

    added the 2nd line. at line 660. made it work.

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

    [2012-05-24 17:12:01] jakubboucek

    Description:
    ------------
    If i use some rules with dots in name like a
    <rule ref="Generic.Files.LineLength">
    then will be library path defined as
    \pear\PHP\CodeSniffer/Standards/Generic/Sniffs/Files\LineLengthSniff.php

    See the shlashes - some is right-shlash, other is backshlash.

    While running test, this rule is ignored.

    Why? Function setTokenListeners() tests, if the sniff's path is in the
    right conventions and check it with DIRECTORY_SEPARATOR. Specifically
    check if the string contains '\Sniffs\'. As I said, this part of string
    is directly defined with / (right-slash). Test fails and Sniff
    definition is ignored.

    The simpliest fix is appending the line above path checking:
    //File: <pear_root>\PHP\CodeSniffer.php:656
    //Notmalize path
    $file = realpath($file);

    Test script:
    ---------------
    ruleset.xml

    <?xml version="1.0"?>
    <ruleset name="Bug check">
    <rule ref="Generic.Commenting.Todo" />
    </ruleset>


    Expected result:
    ----------------
    Registering sniffs in Bug check standard... DONE (1 sniffs registered)

    Actual result:
    --------------
    Registering sniffs in Bug check standard... DONE (0 sniffs registered)

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJun 5, '12 at 12:28a
activeJun 18, '12 at 11:11p
posts2
users2
websitepear.php.net

2 users in discussion

Juanmf: 1 post Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase