CodeSniffer为什么不排除--ignore指定的文件夹?

时间:2012-09-06 11:12:27

标签: php ant jenkins hudson codesniffer

我正在使用Jenkins(Hudson)CI,并且每晚使用许多工具来分析代码,包括用于Checkstyle报告的Codesniffer。 我不想忽略./framework/*目录,但它坚持要包含它,无论我使用--ignore参数做些什么。

报告已成功创建和解析,但由于框架中违反了Pear Coding标准,因此对我们没有任何用处。

可以从我的Ant构建脚本中调用Codesniffer,如下所示:

<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>

我已经尝试了--ignore=framework--ignore=framework/以及上面一行中的所有内容,所有这些都来自我在网络上找到的示例。

我也尝试为每个参数使用不同的行(using < arg value"..." />),但无济于事。

有什么想法吗? 非常感谢:)

编辑: --ignore参数现在是:

--ignore=${basedir}/framework/

......但仍然包含了框架文件夹。有没有人有一个工作的PhpCodeSniffer配置,带有--ignore参数,有效吗?

在这里交叉手指

4 个答案:

答案 0 :(得分:6)

我在詹金斯遇到同样的问题,上面的回答在一定程度上帮助了我。这就是我现在所拥有的(并且适用于我的系统)。

如果你的系统是这样的:

/
/build.xml
/foo
/foo/bar

这就是我在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>

诀窍是不使用$ {basedir}并丢失目录的尾部斜杠。

我希望它有所帮助

答案 1 :(得分:4)

也可以将这些排除项放在build / phpcs.xml中。詹金斯在这里工作得很好。

排除js / facebook目录中的所有文件,js / jquery *的通配符匹配和指定文件名的示例。

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

答案 2 :(得分:3)

使用*将无效,因为shell会扩展它们。

根据您的版本php_codesniffer,您必须传递要忽略的目录的完整路径(旧版本),或者从构建目录传递相对路径以使忽略工作(从php_codesniffer版本1.3.6开启):< / p>

摘自Changelog

  
      
  • 忽略模式现在根据要检查的目录检查文件的相对路径
  •   

答案 3 :(得分:1)

感谢您的投入。我最终解决了这个问题

    <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>

作品!

相关问题