6

我正在使用 Jenkins(Hudson) CI,并且每天晚上使用许多报告工具分析代码,包括 Codesniffer for Checkstyle 报告。我不希望它忽略./framework/*目录,但它坚持包含它,不管我对--ignore参数的努力。

该报告已成功创建和解析,但对我们没有任何用处,因为框架中存在大量违反 Pear 编码标准的情况。

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

<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

4 回答 4

8

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

如果您的系统如下所示:

/
/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} 并丢失目录的尾部斜杠。

我希望它有帮助

于 2012-10-17T10:09:48.963 回答
5

也可以将这些排除项放在 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>
于 2012-10-19T09:32:04.753 回答
3

由于外壳会扩展它们,因此使用*将不起作用。

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

更新日志摘录:

  • 忽略模式现在根据正在检查的目录检查文件的相对路径
于 2012-09-06T12:42:32.407 回答
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>

作品!

于 2012-10-18T12:48:57.463 回答