如何忽略行长度PHP_CodeSniffer [英] How to Ignore Line Length PHP_CodeSniffer

查看:1524
本文介绍了如何忽略行长度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。

And set --standard=/path/to/your/ruleset.xml.

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

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>

这篇关于如何忽略行长度PHP_CodeSniffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆