Question

I am having trouble including external sniffs in my standard. Using the newest version of PHP_CodeSniffer 1.4.3, I can not include a group of sniffs. I can include them individually, but I would like to cut down on my maintenance, and simply only list the ones I do not want.

Working ruleset.xml

<?xml version="1.0"?>
<ruleset name="ICAP Standards">
    <description>ICAP Coding Standards for PHP_CodeSniffer</description>

    <rule ref="Generic.PHP.UpperCaseConstant" />
</ruleset>

This works and includes the simple test. However, I want to include everything in this group, and exclude a single sniff.

Also working ruleset.xml ICAP Coding Standards for PHP_CodeSniffer

    <rule ref="Generic">
        <exclude name="Generic.PHP.LowerCaseConstant"/>
    </rule>
</ruleset>

Non working ruleset.xml

<?xml version="1.0"?>
<ruleset name="ICAP Standards">
    <description>ICAP Coding Standards for PHP_CodeSniffer</description>

    <rule ref="Generic.PHP">
        <exclude name="Generic.PHP.LowerCaseConstant"/>
    </rule>
</ruleset>

This ruleset does not work, and returns an exception when running PHPCS.

PHP_CodeSniffer_Exception: Referenced sniff Generic.PHP does not exist in C:\Program Files (x86)\PHP\pear\PHP\CodeSniffer.php on line 845

This is with version 1.4.3, which was just released, with PHP 5.4.8.

My PHPCS -i does show Generic as an installed standard:

The installed coding standards are ICAP, MySource, PEAR, PHPCS, PSR1, PSR2, Squiz and Zend.

I am working in a mixed environment, and am trying to avoid using paths as much as possible, since they are considerably different between Windows and Ubuntu 12.10.

Était-ce utile?

La solution

This method of exclusion is not supported by PHP_CodeSniffer. The documentation for the ruleset.xml file is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml

In summary, you can only exclude specific sniffs or specific error messages.

I noticed you suggested this as a feature request as well: http://pear.php.net/bugs/bug.php?id=19731

I'm about to have go on an extended break while my wife and I have another baby, but I'll hopefully be able to look into this new type of exclusion when I get back in the new year.

Thanks for posting the feature request.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top