沃梦达 / 编程问答 / php问题 / 正文

如何忽略行长 PHP_CodeSniffer

How to Ignore Line Length PHP_CodeSniffer(如何忽略行长 PHP_CodeSniffer)

本文介绍了如何忽略行长 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>

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

本文标题为:如何忽略行长 PHP_CodeSniffer

基础教程推荐