如何忽略行长 PHP_CodeSniffer

我一直在使用 PHP_CodeSniffer 和 jenkins,我的 build.xml 是为 phpcs 配置的,如下所示

I have been using PHP_CodeSniffer with jenkins, my build.xml was configured for phpcs as below

<target name="phpcs">
    <exec executable="phpcs">
        <arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend ${source}"/>
    </exec>
</target> 

我想忽略以下警告

FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 117 | WARNING | Line exceeds 80 characters; contains 85 characters
--------------------------------------------------------------------------------

如何忽略行长警告?

推荐答案

您可以创建自己的标准.Zend 非常简单(使用 PEAR 安装后,在我的 Debian 安装中位于 /usr/share/php/PHP/CodeSniffer/Standards/Zend/ruleset.xml 中).在此基础上再创建一个,但忽略 line-length 位:

You could create your own standard. The Zend one is quite simple (this is at /usr/share/php/PHP/CodeSniffer/Standards/Zend/ruleset.xml in my Debian install after installing it with PEAR). Create another one based on it, but ignore the line-length bit:

<?xml version="1.0"?>
<ruleset name="Custom">
 <description>Zend, but without linelength check.</description>
 <rule ref="Zend">
  <exclude name="Generic.Files.LineLength"/>
 </rule>
</ruleset>

并设置--standard=/path/to/your/ruleset.xml.

或者,如果您只想在触发之前增加字符数,请重新定义规则:

Optionally, if you just want to up the char count before this is triggered, redefine the rule:

 <!-- Lines can be N chars long (warnings), errors at M chars -->
 <rule ref="Generic.Files.LineLength">
  <properties>
   <property name="lineLimit" value="N"/>
   <property name="absoluteLineLimit" value="M"/>
  </properties>
 </rule>

相关文章