AlexA
AlexA

Reputation: 4118

PHP codesniffer - how to teach it to ignore white space?

I am using PHP CodeSniffer to check if my code complies to Zend standards. 80 chars per line is one of them. But I prefer to indent line with white spaces and sniffer treat short lines with line indentations as long lines.

Is there a way to teach it to ignore whitespace identations? Or it makes sense and the farther my line is indented, the shorter it should be?

Upvotes: 2

Views: 3350

Answers (3)

halfdan
halfdan

Reputation: 34214

Actually this makes perfect sense to keep a line to 80 characters, no matter how many indentations you have.

Upvotes: 1

Ferdy
Ferdy

Reputation: 31

This setting should be in the ruleset.xml withint the Standards/Zend directory, for example /usr/share/pear/PHP/CodeSniffer/Standards/Zend/ruleset.xml

Here will be a block like the following;

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

Update the 'lineLimit' and 'absoluteLineLimit' to your liking. The difference between these two settings is lines exceeding the 'absoluteLineLimit' will trigger errors, while 'lineLimit' only causes warnings.

Indentation is part of a lines length. By default it is impossible to ignore these, though you could write your own sniff if you really want this. But I would advice against it, because it invalidates the whole point of having maximum lengths.

Upvotes: 3

Talvi Watia
Talvi Watia

Reputation: 1080

per codesniffer:docs

When the tab width is set by default, the replacement of tabs with spaces 
can be disabled for a single script run by setting the tab width to zero.

Disabling the replacement of tabs with spaces

$ phpcs --tab-width=0 /path/to/code

This of course won't help you condensing down to 80 col if your tabs/spacing is causing this to happen.

Upvotes: 0

Related Questions