squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Excluding files doesn't work when using STDIN with a filename specified #1208

Closed rkit closed 7 years ago

rkit commented 7 years ago

Excluding files doesn't work when using stdin

Config:

<?xml version="1.0"?>
<ruleset name="Custom Standard">
    <description>A custom coding standard</description>

    <exclude-pattern>*/views/*</exclude-pattern>
    <rule ref="PSR2" />
</ruleset>

Command:

cat /test/views/index.php | phpcs --standard="/test/phpcs.xml" --stdin-path="/test/views/index.php"

And as a result, we got errors.

Is it a known bug? I would like to fix it

PHP_CodeSniffer version 2.7.0 (stable) by Squiz (http://www.squiz.net)
gsherwood commented 7 years ago

PHPCS has always assumed that if you are passing content directly to it, you want it checked no matter what the exclude rules are. I have changed this in 3.0 (due to request #733), but it is a serious backwards compatibility break so it wont be changed in the 2.x version.

If you'd like to try out the current 3.0 RC release, you should find that it works as you expect.

rkit commented 7 years ago

due to request #733

I use this linter for the Atom

If you'd like to try out the current 3.0 RC release, you should find that it works as you expect.

I tried with 3.0.0RC1 and the result is the same, I have got errors.

PHP_CodeSniffer version 3.0.0RC1 (beta) by Squiz (http://www.squiz.net)
gsherwood commented 7 years ago

I tried with 3.0.0RC1 and the result is the same, I have got errors.

Sorry, it was working and I've realised it broke when the stdin-path feature was merged in from master. I've fixed it again now.

rkit commented 7 years ago

Thanks!