Question

I'm using Jenkins(Hudson) CI, and every night analysing the code using a number of tools for repporting, including Codesniffer for Checkstyle reports. I wan't it to ignore the ./framework/* directory, but it insists on including it, regardless of my efforts with the --ignore parameter.

The report is created and parsed successfully, but not really of any use to us because of the extreme amount of violations of the Pear Coding standards in the framework.

Codesniffer is called from my Ant build-script like this:

<target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
 <exec executable="phpcs" dir="${basedir}" output="${basedir}/build/logs/checkstyle.xml" failonerror="off">
  <arg line="--report=checkstyle --standard=${basedir}/build/phpcs.xml --extensions=php  --ignore=*/framework/* ${basedir}" />
 </exec>
</target>

I've tried --ignore=framework, --ignore=framework/, and the one in the line above, all from examples I've found around the web.

I've also tried using a different line for each argument (using < arg value"..." /> ), but to no avail.

Any ideas? Much appreciated :)

Edit: The --ignore argument is now:

--ignore=${basedir}/framework/

...And still, the framework folder is being included. Does anyone out there have a working PhpCodeSniffer configuration, with an --ignore argument, working?

Crossing fingers here

Was it helpful?

Solution

Using * will not work since the shell will expand them.

Depending on your version php_codesniffer you have to either pass the full path to the directory to ignore (older versions), or the relative path from the build directory to make the ignore work (from php_codesniffer version 1.3.6 on):

Excerpt from the Changelog:

  • Ignore patterns now check the relative path of a file based on the dir being checked

OTHER TIPS

I was having the same problem in Jenkins and above answer helped me to some extent. This is what I have now (and works on my system).

If your system looks like this:

/
/build.xml
/foo
/foo/bar

This is what I have in my build.xml

  <target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<exec executable="phpcs">
  <arg value="--standard=${basedir}/build/phpcs.xml" />
  <arg value="--ignore=foo/bar" />
  <arg path="${basedir}" />
</exec>

The trick was not to use ${basedir} and to lose the trailing slash of the directory.

I hope it helps

It's also possible to place these exclusions in build/phpcs.xml. Working fine here in Jenkins.

Examples for excluding all files in js/facebook dir, wildcard match for js/jquery* and a specified filename.

<exclude-pattern>lib/facebook</exclude-pattern>
<exclude-pattern>js/jquery*</exclude-pattern>
<exclude-pattern>lib/Postmark.php</exclude-pattern>

Thanks for the inputs. I ended up solving it like this

    <target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
     <exec executable="phpcs" failonerror="off">
      <arg line="-v --report-checkstyle=${basedir}/build/logs/checkstyle.xml --standard=${basedir}/build/phpcs.xml --extensions=php --ignore=extensions,library ./protected" />
     </exec>
    </target>

Works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top