I'm using the following rule set:
<?xml version="1.0"?>
<ruleset>
<rule ref="PSR2" />
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
</ruleset>
on this example file (I've replaced spaces by 路):
<?php
namespace Example;
class SomeClass
{
路路路路public function someMethod()
路路路路{
路路路路路路路路$var = 2;路路路路
路路路路
路路路路
路路路路}
}
The PSR2 sniffs are executed as expected, while the Squiz.WhiteSpace.SuperfluousWhitespace sniff doesn't seam to be executed.
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
8 | ERROR | [x] Whitespace found at end of line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
As soon as I remove the PSR2 sniff the Squiz.WhiteSpace.SuperfluousWhitespace sniff works and I will also get the other output:
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
8 | ERROR | [x] Whitespace found at end of line
9 | ERROR | [x] Whitespace found at end of line
9 | ERROR | [x] Functions must not contain multiple empty lines in
| | a row; found 2 empty lines
10 | ERROR | [x] Whitespace found at end of line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
I guess this might be related to #317 .
A workaround seams to be to re-enable the sniffs, which are disabled by PSR2:
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
<severity>10</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
<severity>10</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<severity>10</severity>
</rule>
Interesting problem indeed.
I guess this is caused by those lines: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml#L38
The workaround you found is the actual solution. You need to re-enable checks that PSR excludes if you want them in your standard. Although you can set the severity to 5 instead of 10 as this is the default (although it really doesn't matter unless you happen to be using severity filters).
So the individual test suites are not meant to be combined in a modular and isolated manner?
So the individual test suites are not meant to be combined in a modular and isolated manner?
That's exactly how they work, which is why everything had a code, and you can override pretty much everything about an error.
But when you import PSR2, you are necessarily importing all the rules that PSR2 defines, including its exclusions. So you need to override those exclusions if you don't want them, in the same way you'd override methods and properties if you were extending a class; your custom standard is extending PSR2.
This is exactly the same way that you turn PSR2 from a space-indentation standard to a tab-indentation standard: https://gist.github.com/gsherwood/9d22f634c57f990a7c64
Try running PHPCS with the -vv flag and reading the output at the very top. This shows how it is processing your ruleset and what inclusions and exclusions it is making. Maybe that will help make it clear what the difference between sniffs and standards are.
Most helpful comment
A workaround seams to be to re-enable the sniffs, which are disabled by PSR2: