-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
The ignore patterns can also be complete regular expressions. If you do specify a regular expression, be aware that * is converted to .* for the convenience in simple patterns, like those used in the example above. So use * anywhere you would normally use .*.
Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders
I believe it would be good to also mention that this also means that any . characters will need to be escaped - \. - to be seen as a literal ..
I ran into this when running PHPCS over a new sniff I am looking to pull here and couldn't figure out why PHPCS did not examine the file.
phpcs -p -s ./src/Standards/Generic/Tests/CodeAnalysis/AssignmentInConditionUnitTest.phpThe reason was, of course, that the exclude pattern in the PHPCS own ruleset did not escape the dot in the pattern:
<exclude-pattern>*/Standards/*/Tests/*.(inc|css|js)</exclude-pattern>which caused the pattern to match on:
./src/Standards/Generic/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php
I will send in a PR to fix this, but hope that clarifying the wiki instructions will help prevent this for others.
If you like, I can also look into fixing this within the Filter::shouldIgnorePath() method, but that will become more complicated as the code would need to verify if a . is already escaped or not, to determine whether or not to escape it.