Thanks to visit codestin.com
Credit goes to github.com

Skip to content

There is no way to exclude path only from root directory #28158

Open
@erickskrauch

Description

@erickskrauch

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

  1. Make ->exclude() filter applying relatively to root folder, defined by ->in() method.
  2. Allow using absolute paths Finder exclude not working as expected with absolute paths #25945
  3. Document this behavior and add some workaround.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions