Reputation: 2411
I'm using codesniffer in a pre-commit git hook like this
phpcs --standard=PSR2,PSR1 src/
However, I don't like the intend policy with tabs. My problem is I don't find the xml that defines the ruleset. When I try to find the available standards with
phpcs -i
I get The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend
. So, I think there must be somewhere on my disc a folder with xml files defining those standards? Also, MySource seems like a template which I could start with, however, I find none of these files. Codesniffer seems to be installed here: c:\Users\*****\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\
.
Also, I'm using PhpStorm and configured the path to Code Sniffer. Now the IDE is full of warnings, but neither here I understand where it takes its rules from. The configuration is set to "Local" which I don't know where the actual config can be found. Coming from VSCode with prettier + eslint I expect somewhere a config where both the IDE and the automated codesniffing pre-commit follow the same ruleset.
I hope you can help me to warp my head around it. Thanks in advance.
Upvotes: 1
Views: 2090
Reputation: 7222
You shouldn't modify the includes XML files for the standards. Instead, you want to define your own XML file that includes the PSR2 standard and then changes it.
Here is an example one that uses PSR2 but requires tab indents instead of space indents: https://gist.github.com/gsherwood/9d22f634c57f990a7c64
Usage instructions are includes on the gist, although you can instead save this file into your project's root directory and call it phpcs.xml
or .phpcs.xml
and PHPCS will find it automatically when you don't specify a standard to use.
For your IDE, specify the full path to the XML file to have it use the custom standard. Or consult the documentation for the IDE's plugin (if there is some) about how to use a custom ruleset.
Upvotes: 3