Sunday, 5 August 2007

Ignore files and folders with PHP_CodeSniffer

A feature request came through about a month ago to add a new command line argument to PHP_CodeSniffer that allows certain files and folders to be skipped. I added this feature in a couple of weeks ago and I've just finished updating the end user docs to show how it is used.

Sometimes you want PHP_CodeSniffer to run over a very large number of files, but you want some files and folders to be skipped. The --ignore command line argument can be used to tell PHP_CodeSniffer to skip files and folders that match one or more patterns.

In the following example, PHP_CodeSniffer will skip all files inside the package's tests and data directories. This is useful if you are checking a PEAR package but don't want your test or data files to conform to your coding standard.

$ phpcs --ignore=*/tests/*,*/data/* /path/to/code

As it turns out, this feature comes in handy for the new automated PHP_CodeSniffer report being run over PEAR CVS thanks to Brett Bieber.

PHP_CodeSniffer contains a lot of test files that violate the PEAR coding standards for the purpose of checking that violations are detected. Those files were causing thousands of errors to be reported against the PHP_CodeSniffer package, which was not an accurate reflection of its adherence to the coding standards.

Brett has now modified his script to use the new command line argument to ignore all files inside test and data directories, which matches the newly modified PhpDocumentor ignore pattern being used by PEAR.