Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Ignore Line Length PHP_CodeSniffer

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?

like image 991
dextervip Avatar asked Feb 14 '12 16:02

dextervip


People also ask

How do I ignore Phpcs?

With the following comments you can ignore whatever part of a file you would like. With // phpcs:ignore and // phpcs:disable you can also specify which messages, sniffs, categories or standards you would like to disable, for example: // phpcs:ignore Squiz.

What is Phpcbf?

PHP Code Beautifier and Fixer for Visual Studio Code. This extension provides the PHP Code Beautifier and Fixer ( phpcbf ) command for Visual Studio Code. phpcbf is the lesser known sibling of phpcs (PHP_CodeSniffer). phpcbf will try to fix and beautify your code according to a coding standard.


1 Answers

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> 
like image 111
Wrikken Avatar answered Sep 18 '22 23:09

Wrikken