Open
Description
Symfony version(s) affected: 4.1.3
Description
I'm using PHP-CS-Fixer. It's using symfony/finder to create files list, that should be fixed. Some of my projects not using src/
directory for source files, so I need to write some exclude rules. For example:
<?php
$finder = \PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('data')
->exclude('docker')
->exclude('frontend')
->exclude('common/emails')
->exclude('common/templates')
->notPath('#.*/runtime#')
->notPath('#.*/views#')
->notPath('autocompletion.php')
->exclude('tests/codeception/_output')
->notPath('#tests/codeception/.*/_output#')
->notPath('#tests/codeception/.*/_support/_generated#')
->name('yii');
return \Ely\CS\Config::create()
->setFinder($finder);
Rule ->exclude('data')
applies on any directory, so it excluding some nested folders:
api
├── config
│ ├── bootstrap.php
│ ├── config.php
│ └── params.php
├── controllers
│ ├── Controller.php
│ └── SiteController.php
├── data
│ └── test.php
├── models
├── runtime
├── views
└── web
├── assets
├── favicon.ico
└── robots.txt
data
├── ...
In my case, the file api/data/test.php
will not be fixed.
It's also strange, that ->exlude('autocompletion.php')
not working, but ->notPath('autocompletion.php')
works fine.
How to reproduce
Just create alternative folders structure and you will get it.
Possible Solution
- Make
->exclude()
filter applying relatively to root folder, defined by->in()
method. - Allow using absolute paths Finder exclude not working as expected with absolute paths #25945
- Document this behavior and add some workaround.