squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Add support for phpcs.xml.dist files #583

Closed ofbeaton closed 8 years ago

ofbeaton commented 9 years ago

This is a feature request. It is similar to https://github.com/squizlabs/PHP_CodeSniffer/issues/465 however I felt that it was narrow enough that it could be implemented much quicker.

I would like phpcs to pick up a phpcs.xml.dist file if present, but prefer to use the phpcs.xml file if present. This would mimic other PHP phar's that use .xml files for default configuration, like phpunit.

This would allow the phpcs.xml.dist file to be checked in your CVS, while an individual team member could create their own phpcs.xml file to override it. But they would not be required to.

Interestingly this just burned me hard, where I checked out a new project with a "phpcs.xml.dist" file but forgot to copy it to "phpcs.xml". I then ran "phpcs", and it seemed to just hang. Devoid of any parameters, it just sat there doing nothing, providing no output. I spent a good half hour trying to figure it out until I realized what the problem was.

Btw, I love the new code fixer (phpfcb), though I wish it's name wasn't so similar to the "phpcb" phar for Code Browser that is also often used along with Code Sniffer.

gsherwood commented 8 years ago

I've added this feature now. As you've said, phpcs.xml is preferred over phpcs.xml.dist.

ofbeaton commented 8 years ago

Thank you! Very welcome change.

pfrenssen commented 8 years ago

Great! thanks a lot!

alexpott commented 8 years ago

Thanks we're just incorporating phpcs into Drupal's continuous integration.

kminh commented 8 years ago

I'm still using 2.3.4 for compatibility with https://github.com/wimg/PHPCompatibility, but I would like to use a phpcs.xml.dist file as well (only available since 2.5.0). Is there a way around this?

gsherwood commented 8 years ago

@kminh Not from a PHP_CodeSniffer point-of-view. If the feature exists in a newer PHPCS version, you need to upgrade to use it.

I'd recommend speaking to the maintain of the PHPCompatibility standard and asking if they support the latest PHPCS version. I have no idea what specifically would be stopping that.

pfrenssen commented 8 years ago

@kminh it seems like they just need to update the composer.json file. Can you check if https://github.com/wimg/PHPCompatibility/pull/106 solves it for you? I haven't tested it but I don't see why it shouldn't work. At first glance it doesn't seem that anything added in PHP_CodeSniffer 2.5.0 would break it.

kminh commented 8 years ago

@pfrenssen thank you for creating the pull request. I might simply fork PHPCompatibility if your pull request is not merged.