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.66k stars 1.48k forks source link

Ignore folder but not sniff/ruleset #1059

Closed MaartenStaa closed 8 years ago

MaartenStaa commented 8 years ago

Hi,

I have a custom standard under folder foo. It contains the ruleset.xml file and modified versions of certain sniffs, as well as custom ones.

I would like to run phpcs with --ignore=foo,vendor to not sniff files under those two folders, but it results in 0 warnings and errors every time, since foo is also the name of the ruleset. Is there a way around this?

Thanks.

photodude commented 8 years ago

try the following in your ruleset

<!-- Exclude folders not containing production code -->
    <exclude-pattern>*/foo/*</exclude-pattern>
    <exclude-pattern>*/vendor/*</exclude-pattern>

from the command line I think you would do --ignore=*/foo/*,*/vendor/*

gsherwood commented 8 years ago

On the command line, you can also run with --ignore=*/foo/*,*/vendor/*.

Note that the folder name you are ignoring and the name of the standard you are using are not related in any way inside PHP_CodeSniffer, so you aren't telling PHPCS to ignore your standard while checking files.

If you want to see what PHPCS is checking, run it with the -v command line argument and it will show how many files it found to check, how many sniffs it is using for checking, and the results of each file it checked.

MaartenStaa commented 8 years ago

Thanks, that seemed to work after some tinkering. The project is actually also under a directory called foo, and just --ignore=*/foo/*,*/vendor* was also producing a shell error (zsh).

In the end the solution was to use --ignore="pwd/foo/*,pwd/vendor/*".