我使用Jenkins(Hudson)CI,每天晚上都使用许多用于重新移植的工具来分析代码,包括用于Checkstyle报告的Codesniffer。我不希望它忽略./framework/*
目录,但它坚持包含它,不管我在--ignore
参数上做了什么努力。
该报告创建和解析成功,但对我们没有任何用处,因为该框架中存在大量违反梨编码标准的行为。
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参数,有效?
交叉手指此处
我在Jenkins遇到了同样的问题,上面的回答在一定程度上帮助了我。这就是我现在所拥有的(并且在我的系统上工作)。
如果你的系统看起来像这样:
/
/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}并丢失目录的尾部斜杠。
我希望它能帮助
也可以将这些排除项放在build/phpcs.xml中。
排除js/facebook-dir中所有文件的示例,js/jquery*的通配符匹配和指定的文件名。
<exclude-pattern>lib/facebook</exclude-pattern>
<exclude-pattern>js/jquery*</exclude-pattern>
<exclude-pattern>lib/Postmark.php</exclude-pattern>
使用*
将不起作用,因为shell将展开它们。
根据您的版本php_codesniffer,您必须传递要忽略的目录的完整路径(旧版本),或者传递构建目录的相对路径以使忽略生效(从php_codesiniffer 1.3.6版本开始):
变更日志摘录:
- 忽略模式现在根据检查的目录检查文件的相对路径
感谢您的输入。我最终像这个一样解决了它
<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>
工作!