Skip to content
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

No longer reading phpcs.xml #1660

Closed
anhskohbo opened this issue Sep 17, 2017 · 6 comments
Closed

No longer reading phpcs.xml #1660

anhskohbo opened this issue Sep 17, 2017 · 6 comments

Comments

@anhskohbo
Copy link

I upgrade phpcs 3.0.2 today and see the php no longer read phpcs.xml.dis file.

phpcs -i

The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend, WordPress-Extra, WordPress-Docs, WordPress-VIP, WordPress-Core and WordPress

Run:

phpcs awebooking.php

FOUND 70 ERRORS AND 4 WARNINGS AFFECTING 35 LINES
....

My phpcs.xml.dist

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
	<description>Generally-applicable sniffs for WordPress plugins</description>

	<config name="testVersion" value="5.6-7.1" />
	<rule ref="PHPCompatibility" />

	<rule ref="WordPress-Core">
		<exclude name="Generic.Files.LowercasedFilename.NotFound" />
		<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
		<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
		<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeKeyFound" />
	</rule>

	<rule ref="WordPress-Docs">
		<exclude name="Squiz.Commenting.FileComment.Missing" />
		<exclude name="Squiz.Commenting.ClassComment.Missing" />
		<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" />
	</rule>

	<exclude-pattern>*/vendor/*</exclude-pattern>
	<exclude-pattern>*/tests/*</exclude-pattern>
</ruleset>
@gsherwood
Copy link
Member

PHPCS definitely still reads phpcs.xml.dist files. That's how I test PHPCS itself: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist

Try running phpcs with the -vv command line argument. There will be a lot of output, but the top section will show you what ruleset was processed and what rules were included. That might provide more info.

@anhskohbo
Copy link
Author

I have try with --v and it use default PSR-2 as default. Just rollback to v2.x and it work.
Or maybe only happen in my machine (Arch Linux), waiting for someone have same issue

@nosilver4u
Copy link

I'm running a similar config with the same exclude patterns and the exclude-pattern directives are definitely not working as before. 2.x works fine, but Travis CI is of course using the latest phpcs, so my builds are now failing horribly.

@jrfnl
Copy link
Contributor

jrfnl commented Sep 18, 2017

@anhskohbo @nosilver4u Could you each provide links to the repos you are running PHPCS on ? And maybe a link to one of the failed Travis builds ? I'd like to take a look.

@nosilver4u
Copy link

My build is here: https://travis-ci.org/nosilver4u/ewww-image-optimizer/builds/277064437
Repo at https://github.com/nosilver4u/ewww-image-optimizer

I found a fix was to change the way I run the phpcs command. Previously, it was run like so
phpcs --standard=phpcs.ruleset.xml $(find . -name '*.php')
I changed it to this and it worked:
phpcs --standard=phpcs.ruleset.xml --extensions=php .

In the first case, phpcs would be passed a list of files to validate, potentially breaking the exclude pattern. In the latter, it simply has a directory as the target, and is able to ignore the files that match the exclude-pattern properly. And as I said before, my exclude patterns are identical to those used by anhskohbo. Hope that helps!

@gsherwood
Copy link
Member

I finally know what is happening here. In your version, if you've told PHPCS that your default standard is PSR2, it will always default to using PSR2. If you haven't told it what standard to use, either via the config or on the command line, it will go searching for a phpcs.xml file.

I noticed this and fixed it in the 3.1.0 release via this commit: 2e34a66

If you upgrade to 3.1.0, this will be fixed for you. If you can't upgrade, you could remove the default_standard config setting as a workaround.

Closing this issue as I've been able to confirm the problem on 3.0.2 and the fix in 3.1.0 on my own test system.

underthecocotree added a commit to underthecocotree/php-censor that referenced this issue May 16, 2018
I thought I had the standard path wrong but after updating php_codesniffer from composer it started reading phpcs.xml.

Ref:
squizlabs/PHP_CodeSniffer#1660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants