There are some discrepencies between the results when you run:

phpcs -n --standard=Drupal --extensions=php,module,install,test,profile,theme [foldername]

and when just running the code sniffer pre-commit hook with:

drush coder-review --git

To get around this, I've added the --sniffer option for my pre-commit hook (to run the PHP CodeSniffer review):

drush coder-review --sniffer --git

The problem is that PHP CodeSniffer checks ALL files, even those with irrelevant extensions, when you aren't checking a folder. This means I was getting pre-commit errors on things like gifs and pngs and couldn't commit!

I created a patch to check for these extensions in the pre-commit, which I will attach in the next comment, in case anyone else would find it useful.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mariacha1’s picture

Here is the patch.

douggreen’s picture

Did you test why CoderReviewCodeSnifferClient didn't handle the allowed extensions? That seems to be where I tried to handle it.

mariacha1’s picture

I might be misunderstanding what CoderReviewCodeSnifferClient does, but as far as I can tell it looks like it just turns the command line into the phpcs object. Once it's finished, it essentially passes this:

phpcs -n --standard=Drupal --extensions=php,inc,module,install,test,profile,theme path/to/my/image.png

The problem is that php-codesniffer only checks extensions if it is passed a folder. See:

http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php

"<extensions> A comma separated list of file extensions to check (only valid if checking a directory)"

Since I'm not checking a folder but a file, the extensions are ignored. The only way I can see to keep these files from being checked is to never send them to phpcs to begin with.

There might be better solutions, of course.

mariacha1’s picture

I just discovered that my previous patch didn't work, and was, in fact, keeping the sniffer from running at all! So, here's an updated patch that seems to be working -- the results are matching up with what I see when running phpcs, but the sniffer isn't checking files that it shouldn't (like pngs).

klausi’s picture

Component: Coder Sniffer » Coder Review
Issue summary: View changes
klausi’s picture

Status: Needs review » Closed (won't fix)

Coder 7.x is frozen now and will not receive updates. Coder 8.x-2.x can be used to check code for any Drupal version, Coder 8.x-2.x also supports the phpcbf command to automatically fix conding standard errors. Please check if this issue is still relevant and reopen against that version if necessary.