How to Ignore Line Length PHP_CodeSniffer

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

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>  

And I would like to ignore the following warning

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

How could I ignore the line length warning?

回答1:

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> 

And set --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> 


回答2:

  1. locate PEAR/ruleset.xml or sudo find / -name "ruleset.xml"

  2. Then you need to find the following lines in the ruleset.xml:

    <!-- Lines can be 85 chars long, but never show errors --> <rule ref="Generic.Files.LineLength"> <properties> <property name="lineLimit" value="85"/> <property name="absoluteLineLimit" value="0"/> </properties> </rule>

  3. Just change the number 85 (max length of the line) to what you want.

Notice that the phpc's default coding standard is the PEAR standard. So you need to edit ruleset.xml at this location: CodeSniffer/Standards/PEAR/ruleset.xml



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!