phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

phpcs custom ruleset #310

Closed cschalenborgh closed 7 years ago

cschalenborgh commented 7 years ago
Q A
Version ^0.11.2
Bug? no
New feature? yes
Question? yes

Is there a way to submit a custom ruleset for phpcs? Seems like the ruleset parameter is not available for phpcs as it is for phpmd.

I'd like to ignore this error: 28 | WARNING | Line exceeds 120 characters; contains 124 characters 36 | WARNING | Line exceeds 120 characters; contains 135 characters 39 | WARNING | Line exceeds 120 characters; contains 133 characters 42 | WARNING | Line exceeds 120 characters; contains 146 characters 45 | WARNING | Line exceeds 120 characters; contains 150 characters 48 | WARNING | Line exceeds 120 characters; contains 145 characters

This should solve it, but how do I add this ruleset to phpcs? http://stackoverflow.com/a/9281546

veewee commented 7 years ago

Hi @cshalenborgh,

You can just point to the phpcs.xml file in the standard option as described in the documentation: https://github.com/phpro/grumphp/blob/master/doc/tasks/phpcs.md

cschalenborgh commented 7 years ago

Thanks veewee, I didn't realise it also accepted paths. It's working now! Is it also possible to submit multiple rulesets, and let the latter ones overrule the others (if duplicate). I currently solved it by downloading the PSR2 ruleset, and changing some rules to fit our project requirements.

phpcs: standard: ['PSR2', 'phpcs_custom_ruleset.xml']

jyggen commented 7 years ago

The better option is probably to just inherit PSR-2 in your custom ruleset, like so:

<?xml version="1.0"?>
<ruleset name="Custom Standard">
    <rule ref="PSR2"/>
    <!-- Add custom rules or tweak PSR-2 here -->
</ruleset>
veewee commented 7 years ago

This package only supports the parameters that are available on the commandline tool itself: https://pear.php.net/manual/en/package.php.php-codesniffer.usage.php There is no way to specify multiple standards, so as @jyggen mentions, you should extend the PSR2 standard in your XML file.

cschalenborgh commented 7 years ago

Works, thanks!