phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

PHP CS Fixer V2 (and V1) - unable to ignore files #409

Closed Rastusik closed 7 years ago

Rastusik commented 7 years ago
Q A
Version ?
Bug? no
New feature? no
Question? yes
Documentation? no
Related tickets /

Hi, I'd like to have an option to be able to exclude selected files from PHP CS Fixer scan. Would that be possible?

Thanks

Landerstraeten commented 7 years ago

Hi @Rastusik,

You need to create a config file for PHP CS Fixer.

Inside that config file, you should create a Finder where you can exclude() folders or use notPath() for specific files.

$finder = PhpCsFixer\Finder::create()
    ->exclude('somedir')
    ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
    ->in(__DIR__);

More info on https://github.com/FriendsOfPHP/PHP-CS-Fixer just above the caching title and on http://symfony.com/doc/current/components/finder.html

Rastusik commented 7 years ago

Hi @Landerstraeten,

are you sure about this? I already tried that and it didn't work. The point is that the files that need to be checked are being fetched from GitPreCommitContext (https://github.com/phpro/grumphp/blob/master/src/Task/PhpCsFixerV2.php#L69) and then this code gets triggered: https://github.com/phpro/grumphp/blob/master/src/Task/AbstractPhpCsFixerTask.php#L118 which will create a separate process for each file added to git index. I think the FileFinder is skipped in this process.

Or did I do something wrong? Maybe somebody could test this as well, to confirm?

Landerstraeten commented 7 years ago

Which (exact) version of grumphp and php-cs-fixer are you using? Can you also post your grumphp.yml and .php_cs configuration?

Rastusik commented 7 years ago

oh, I wasn't on the 0.12 version of grumphp, I was on 0.11.6 ... thanks for help