[英]Symfony Finder exclude with glob
I am trying to run PHP CS Fixer, which I believe is based on Symfony (which I am not familiar with), and having a problem with excluding some paths. 我正在尝试运行PHP CS Fixer,我认为它基于Symfony(我不熟悉),并且在排除某些路径时遇到问题。
My setup is below: 我的设置如下:
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('lib/adodb')
->exclude('lib/bbcode')
->exclude('lib/joomla')
->exclude('lib/JSON')
->exclude('lib/pear')
->exclude('lib/phpass')
->exclude('lib/smarty')
->exclude('lib/smtp')
->exclude('modules/*/lib')
->name('*.class')
->name('*.inc')
->name('*.php')
;
Basically, I will like to exclude: 基本上,我想排除:
modules/ANYNAME/lib/ANYFILE
modules/ANYNAME/lib/ANYSUBDIR/ANYFILE
But I find that the ->exclude('modules/*/lib')
line is not catching these. 但我发现
->exclude('modules/*/lib')
行没有抓住这些。 For instance, modules/somemodule/lib/somefile.inc
is still processed. 例如,仍然处理
modules/somemodule/lib/somefile.inc
。
I had thought that this was because I had ->name('*.inc')
but it seems to happen with or without that line. 我曾经以为这是因为我有
->name('*.inc')
但似乎有或没有那条线。
The other excludes work fine except the ->exclude('modules/*/lib')
one. 另一个排除工作正常,除了
->exclude('modules/*/lib')
之一。
Any pointers? 有什么指针吗?
It does seem that the issue is with the name selector. 似乎问题在于名称选择器。 Seems it is not allowed to select
*.inc
using name
for instance and then try to exclude those found in modules/xyz/lib
. 似乎不允许使用
name
选择*.inc
,然后尝试排除在modules/xyz/lib
找到的那些。
Overcoming this would solve my issue 克服这个问题可以解决我的问题
PHP CS Fixer could accept any iterable as finder. PHP CS Fixer可以接受任何iterable作为finder。 Indeed, default one is just a symfony/finder ( https://github.com/symfony/finder/blob/master/Finder.php ).
实际上,默认的只是一个symfony / finder( https://github.com/symfony/finder/blob/master/Finder.php )。
As you can see, exclude
is not accepting a glob. 如您所见,
exclude
不接受glob。 You could use, eg, notPath
: 你可以使用,例如,
notPath
:
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('#modules/.*/lib#')
->name('*.inc');
Let say you have following structure: $ ls -lR .: total 8 drwxr-xr-x 2 keradus keradus 4096 Mai 5 20:32 a drwxr-xr-x 3 keradus keradus 4096 Mai 5 20:31 modules 假设您有以下结构:$ ls -lR .:总计8 drwxr-xr-x 2 keradus keradus 4096 Mai 5 20:32 a drwxr-xr-x 3 keradus keradus 4096 Mai 5 20:31模块
./a:
total 4
-rw-r--r-- 1 keradus keradus 24 Mai 5 20:35 a.inc
./modules:
total 4
drwxr-xr-x 3 keradus keradus 4096 Mai 5 20:31 ANYNAME
./modules/ANYNAME:
total 4
drwxr-xr-x 3 keradus keradus 4096 Mai 5 20:31 lib
./modules/ANYNAME/lib:
total 8
-rw-r--r-- 1 keradus keradus 24 Mai 5 20:35 b.inc
drwxr-xr-x 2 keradus keradus 4096 Mai 5 20:32 sub
./modules/ANYNAME/lib/sub:
total 4
-rw-r--r-- 1 keradus keradus 24 Mai 5 20:35 c.inc
Even when all of that 3 files violates coding standards, only one (not excluded by finder) would be fixed: 即使所有3个文件都违反了编码标准,也只会修复一个(未被发现者排除):
$ php-cs-fixer fix --dry-run -vvv
Loaded config default from "/home/keradus/tmp/.php_cs.dist".
F
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
1) a/a.inc (braces)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.