squizlabs/PHP_CodeSniffer — pull request #38 by cyberwolf (2012-07-11 12:32:15+00:00)
Title: Use relative file path when matching with ignore patterns

Currently the full, absolute path of a file is matched with the ignore
patterns, which makes it difficult to specify patterns to ignore
specific directories in a reusable way.

For example when running phpcs on a Drupal-based project located at
"/home/cyberwolf/myproject/", you'd like to ignore the "includes"
directory in the root of your project, because it contains Drupal core
code. However, other non-core directories can contain a directory
called "includes" as well, which you do not want to ignore while
scanning, for example
"/home/cyberwolf/myproject/sites/all/modules/foo/includes". Currently,
to accomplish this, an ignore pattern with the absolute path needs to
be specified, for example "/home/cyberwolf/myproject/includes". This is
not reusable on other systems where the project might be checked out at
another path. Specifying "includes" would lead to phpcs also ignoring
"/home/cyberwolf/myproject/sites/all/modules/foo/includes".

This patch makes the file path being matched with the ignore patterns
relative to the directory specified for scanning, so "includes" will be
used for matching instead of "/home/cyberwolf/myproject/includes",
"sites/all/modules/foo/includes" will be used for matching instead of
"home/cyberwolf/myproject/sites/all/modules/foo/includes", and so on.
Using "^includes" as an ignore pattern now will succesfully ignore
everything in the "/home/cyberwolf/myproject/includes" dir and nothing
else.