How to Ignore Line Length PHP_CodeSniffer How to Ignore Line Length PHP_CodeSniffer jenkins jenkins

How to Ignore Line Length PHP_CodeSniffer


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>


An alternative way of ignoring the message Line exceeds x characters is to use the --exclude flag to exclude the rule.

vendor/bin/phpcs --standard=PSR2  --exclude=Generic.Files.LineLength app/

In order to find the rule name to exclude, find your corresponding ruleset in following directory:

vendor/squizlabs/php_codesniffer/src/Standards/<coding standard>/ruleset.xml

The rule name will be in the ref node:

 <rule ref="Generic.Files.LineLength">        <properties>            <property name="lineLimit" value="120"/>            <property name="absoluteLineLimit" value="0"/>        </properties> </rule>

It's quicker & less cumbersome than creating a separate ruleset.


  1. Find file CodeSniffer/Standards/PEAR/ruleset.xml – on mac/linux you can search in terminal:

    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