Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #19498 CodeSniffer.php and DIRECTORY_SEPARATOR change causing sniffs to be disregarded
Submitted: 2012-07-10 01:20 UTC
From: thinice Assigned: squiz
Status: Duplicate Package: PHP_CodeSniffer (version 1.3.4)
PHP Version: 5.3.14 OS: Windows
Roadmaps: (Not assigned)    
Subscription  


 [2012-07-10 01:20 UTC] thinice (Justin Rovang)
Description: ------------ On Line 835 on CodeSniffer.php, the recent diff changed the line from: $path = realpath(dirname(__FILE__).'/CodeSniffer/Standards/'.$path); to: $path = realpath(dirname(__FILE__).'/CodeSniffer/Standards').DIRECTORY_SEPARATOR.$path; It should read something like this: $path = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'CodeSniffer'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR.$path); There are several other lines in this file that are similar that may need to be looked into as well - but I just had a bear of a time tracking this issue down. You end up with a return value of this, i.e: "D:\CODE\DevTools\pear\PHP\CodeSniffer\Standards\PEAR/Sniffs/Functions/ValidDefaultValueSniff.php" The problem is (at least in Windows), when the array from the getSniffs() call is used in setTokenListeners() (Approx Line 659) - the $sniffPos var is coming up with dud results because of the mixed separators in the path. Test script: --------------- I added echo "Garbaging: ".$file." "; To the conditional starting at Line 659 of CodeSniffer.php to verify that a lot of sniffs are being discarded because of the mixed directory separators in the sniff processing.

Comments

 [2012-07-10 01:22 UTC] thinice (Justin Rovang)
That's @834, not @835 with the $path assignment. **
 [2012-07-10 01:26 UTC] thinice (Justin Rovang)
-Status: Open +Status: Critical
 [2012-07-10 01:26 UTC] thinice (Justin Rovang)
-Summary: CodeSniffer.php and DIRECTORY_SEPARATOR causing issues +Summary: CodeSniffer.php and DIRECTORY_SEPARATOR change causing sniffs to be disregarded
 [2012-07-10 04:21 UTC] squiz (Greg Sherwood)
-Status: Critical +Status: Open -Assigned To: +Assigned To: squiz
Please don't set the severity of bug reports. I look at all of them no matter what they are.
 [2012-07-10 06:27 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Feedback
I've run the latest git clone version of PHP_CodeSniffer on both Windows and OS X and get exactly the same results when testing the PEAR, Squiz, Zend and Generic coding standards over the CodeSniffer.php file. To check, I used the -v command line argument so it tells me exactly how many sniffs were found and registered. The number of sniffs was the same each time and the number of errors, warnings and notices was also the same. Are you using the git clone or a PEAR package? If you have patched your own install, did you just patch this one change or did you patch all fixes (this issue was fixed with other previous changes that appear unrelated)? What standard are you testing with and how many sniffs are registered on Windows vs whatever other OS you are comparing the results on? Sorry for the bunch of questions, but I can't fix this unless I can replicate it.
 [2012-07-10 09:23 UTC] thinice (Justin Rovang)
- This is with the PEAR package. - I patched the one line @834 to fix the issue using the line in my report - The standard I'm using is home brew and installed in the Standards directory alongside Squiz, Generic, PEAR, etc. - The standard is the only extra standard not distributed with PEAR - The standard has a few custom sniffs, with the majority being referenced by the ruleset.xml, most come from Squiz. - The Sniffs also all report back for me (which is why it was a bear to find) - Come run time, the only Sniffs that run are the ones that are custom (inferred via directory structure, not from the ruleset.xml) I will try to put together a test case and package it up for sample.
 [2012-07-10 09:48 UTC] squiz (Greg Sherwood)
The patch you applied is likely the problem. Even though that one line needed to be correct to fix that bug, previous fixes made since the release also contributed to the fix. Please test with the latest git clone to ensure you have all Windows fixes. If you want to install from a git clone: git clone git://github.com/squizlabs/PHP_CodeSniffer.git cd PHP_CodeSniffer pear uninstall php_codesniffer pear install package.xml Or, just run PHPCS directly from the clone, so it doesn't touch your installed version; git clone git://github.com/squizlabs/PHP_CodeSniffer.git cd PHP_CodeSniffer php scripts/phpcs ...
 [2012-07-10 09:58 UTC] thinice (Justin Rovang)
I've verified this on two windows machines. Both were running the PEAR installed 1.3.3 and working correctly. When upgraded to 1.3.4 the issue is consistent. I actually have this set up in a large source control tree for a developer toolset for my team. Here's links to output using a patch. PATCH: https://rovangju.s3.amazonaws.com/misc/phpcs/PHPCS-1.3.4_skipped_sniff_verbosity.patch ================================ OUTPUTS (using -vvv and patch, the registered sniff lists on top are the focus obviously) ================================ Custom standard: https://rovangju.s3.amazonaws.com/misc/phpcs/OUTPUT-skipped_sniff_verbosity_added.txt https://rovangju.s3.amazonaws.com/misc/phpcs/OUTPUT-line_849_patched.txt Using the included Squiz standard with patch: https://rovangju.s3.amazonaws.com/misc/phpcs/OUTPUT-Squiz-skipped_sniff_verbosity_added.txt ============================= STANDARD: ============================= For brevity, this is the full standard which is installed to the 'Standards' dir for PHPCS: https://rovangju.s3.amazonaws.com/misc/phpcs/MState.zip
 [2012-07-10 09:59 UTC] thinice (Justin Rovang)
I will fire up a fresh windows VM and install PHPCS via PEAR to be as objective as possible and report back when I get a chance.
 [2012-07-10 10:01 UTC] thinice (Justin Rovang)
My previous comments are not regarding the git copy you just mentioned - Just to ensure there's no race condition in our communication :) I'll test now with the git copy.
 [2012-07-10 10:07 UTC] thinice (Justin Rovang)
Git copy works without issues. Should I start to make it practice to just get the copy from the Squizlabs git repo? I'm not attuned to how the release cycle is for PHPCS on Pear but it looks like there's some good upgrades sitting out there in your git repo (PSR1/2, etc)
 [2012-07-10 10:13 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Duplicate
Glad the clone is working for you. Thanks for getting back to me. The git repo is always stable code and you can use it at any time. I release and work on PHPCS when I get time, and my time is quite limited at the moment. But there will be a release sometime this week if I get a break. Going to mark this as a duplicate of bug 19471.