Php-cs-fixer: exclude/notPath disregarded

Created on 22 Mar 2019  路  4Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

For configuration or updating questions please read the README and UPGRADE documentation,
or visit: https://gitter.im/PHP-CS-Fixer

When reporting an issue (bug) please provide the following information:

The PHP version you are using ($ php -v):

=> 7.2.11

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=>2.14.2

The command you use to run PHP CS Fixer:

=> php php-cs-fixer.phar --verbose fix --dry-run

The configuration file you are using, if any:

=> ....................................
$finder = PhpCsFixer\Finder::create()
    ->exclude('bootstrap/cache')
    ->in([
        'bootstrap',
    ]);
return PhpCsFixer\Config::create()
    ->setRules([
                // many rules
        ],
    ])->setRiskyAllowed(true)->setFinder($finder);

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
=> n/a
  • with unexpected changes applied when running PHP CS Fixer:
=> ....................................
$ php php-cs-fixer.phar --verbose fix --dry-run
Loaded config default from "C:\mypath\www\.php_cs".
Using cache file ".php_cs.cache".
SFFSS
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
   1) bootstrap\cache\packages.php (...)
   2) bootstrap\cache\services.php (...)

Checked all files in 0.084 seconds, 12.000 MB memory used
  • with the changes you expected instead:
    => I would expect that the whole /cache folder would be excluded. I also tried to explicitly excluding bootstrap/cache/packages.php and bootstrap/cache/services.php using ->notPath, but the result is exactly the same.
    I read #2956 before, but as shown in my example I do not include any path, so exclude rule should work properly.
kinquestion

All 4 comments

When using exclude you have to use relative path: https://api.symfony.com/4.0/Symfony/Component/Finder/Finder.html#method_exclude

So replace ->exclude('bootstrap/cache') with ->exclude('cache') and it will work.

Closing as answered. Feel free to continue discussion, anyway

Oh, makes sense. Thanks for pointing it out.

What if I want to include a and b including a/c but not b/c?

What if I want to exclude only a/c and not a/b/c?

Also the path seems to change when switching to and from cache?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

Bilge picture Bilge  路  3Comments

amitbisht511 picture amitbisht511  路  3Comments

OskarStark picture OskarStark  路  3Comments

ndench picture ndench  路  3Comments