-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Difference between 2 installs of PHPCS #254
Comments
Is it possible that different versions of PHP are being used? One way to compare the installs is also to use the -vv command line argument. This will show how the custom ruleset was included and how each file was tokenized, to confirm that PHPCS is seeing the file in the same way. If you use -vvv it will also show each sniff that is being processed on each token. It might be a bit much to read through manually, but doing a diff on the output might uncover a problem. |
PHP version on the Mac:
And on the server:
|
The out put using -vv on the mac states:
And on the server:
|
If you just use the basic -v option, the output will include something like:
Do you see the same number of sniffs registered between installs? If so, the only thing left is to compare the output of -vvv and check that it is the same, unless the custom coding standard happens to have unit tests you can run to compare results. |
AH HA!! So, I piped the output into txt files and diff'd them and it appears that the local install is not loading any additional Sniffs...
On the local install are all blank...? On the server there's a whole bunch Sniffs included. So while I can run PHPCS from comandline on the mac, and use the standard it doesn't find the Standard's included Sniffs! Any suggestions? |
Stupid question, but I have to ask: are their sub-directories and files inside the CakePHP/Sniffs directory? I imagine there are given the ruleset.xml file obviously exists, but worth checking permissions maybe. I've cloned the CakePHP coding standard repo and can use it as a custom coding standard when specifying the full path. Are you able to specify the full path to the CakePHP directory and have it work on your Mac? If so, I'll need to check a composer install of the CakePHP standard and see where the files are going. If you can provide your composer file, that would be very helpful. I wont get a chance to look at it tonight, but I will try for tomorrow. |
Yep the Sniffs are in the folder.
And it still reports no errors, and still doesn't load the full 65 Sniffs... This is my main composer file:
The thing that is confusing me is that I installed them in basically exactly the same way, and am running them the same way... I'm wondering if it's some path setting or the like? |
I have found the issue!! So basically, if you install the Standard into your .composer folder it is 'technically' in a hidden folder and line 710 of CodeSniffer.php filters Sniff paths out that are in hidden folders. Simple fix is to install the standard somewhere else! All working as expected now! |
Sorry, I should have remembered this one. Someone else had the same problem and I've committed a fix that was contributed to solve this issue. Now, only the top most directory is checked to see if it is hidden. The fix will be released in the next versions, hopefully released this week or next. Thanks for all the help sorting this out. |
No worries! Thanks for your swift support and help! Keep up the fanastic work! |
For my projects I specify dependency on a coding standard in project's own |
Yeah that idea did cross my mind, but I use the same standard for a range of projects so decided it was overkill... |
However to make sure, that both standard parts work (one that doesn't fix and one that fixes) I had to ensure that:
|
Since error reporting code is usually buried deep in the sniff code the idea of having 2 different classes where I have sub-class for PHPCS 2.x that does fixing seemed like too much to me. |
That's great - not sure what it has to do with this issue tho? |
Ah, there was another issue where guy wanted to make sure standard works across different PHPCS versions. I guess I've added comment to wrong issue :) |
I'm having the same issue here. I'm using I've installed On Ubuntu machines, I've checked about the hidden folder with
Any help would be appreciated. |
@desaiuditd if you think different PHPCS installs are processing your files differently, use the If these looks exactly the same, run |
Hi @gsherwood Thanks for reverting back. I checked up the same following the above discussion. Here is the diff report between two installs. Verbose Output: https://www.diffchecker.com/iqnwn0y2 Configs: https://www.diffchecker.com/jb6as1pm It looks like they both are same except the path where I've installed them. |
I see 2 extra spaces on right side, when processing tokenized file. |
Is it a significant diff ? I mean, I thought it is a part of source code file, so it should not matter. |
If the PHPCS config, sniffs used, file analyzed are the same, then result should be the same. Such small diff in analyzed file might cause sniff to behave differently. Try using file with 2 extra spaces on other computer. |
The indentation of the 2 files looks different. If you check line 104 of your output, you see: Thanks for posting that output. The problem with the code you've posted is very clear from it: You've told PHP_CodeSniffer to use a tab width of 4 spaces, so the second bit of code is converted from 4 spaces into a single tag. But the first bit of code only has two spaces, so it is not a full tab wide. It is not converted at all, and left as 2 spaces. So PHPCS is comparing 2 spaces vs 1 tab. Because of this, PHPCS is generating an error for the first piece of code (it is using 2 spaces for the line indent instead of a tab) but the second looks fine once spaces are replaced with tabs. If you want to generate the same errors, you can do one of two things:
For other code you are checking, I'm not sure if this will be the problem (I'd have to see the output when run on that specific code) but I can tell you that your PHPCS installs are working correctly from what you have been able to post. |
True. And I tried the same thing. My files are under version control. And on both the machines I pulled the same commit and checked up. I guess all other errors showed correctly except only one thing below. There are a few files with
So is this particular ruleset is supposed to be special or am I missing something on this again ? Thanks for the clarification though, @gsherwood @aik099 |
Here's the diff for the above issue with no php code issue. https://www.diffchecker.com/6jwfupky |
Are the short_open_tag settings of your PHP installs different by any chance? Maybe run Note that you can mute that error in a custom ruleset.xml file by setting the severity of the |
Ah ! Tricky Catch. Thanks again. Help much appreciated. 👍 |
No problem, glad we've worked it out. |
I have installed PHPCS on my local Mac and on a webserver running Centos 6, both via Composer and both using same version of PHPCS. I have then added an aditional Standard to both, again both from same source, same version etc.
When I run PHPCS against the same files the version on my Mac returns considerably less errors than the same files on my server?
This is the command I am running on the server:
./phpcs --standard="/var/www/html/ci.devapps.mmu.ac.uk/standards/vendor/cakephp/cakephp-codesniffer/CakePHP" /var/www/html/devapps.mmu.ac.uk/events/Controller/EventsController.php
Which generates:
FOUND 18 ERROR(S) AFFECTING 18 LINE(S)
And this is what I am running on the mac:
./phpcs --standard=CakePHP /Users/toby/Server/Sites/events/Controller/EventsController.php
But this reports nothing and indicates that it passes?
Can anyone suggest why they would be differing?
The text was updated successfully, but these errors were encountered: