-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
There is no way to exclude path only from root directory #28158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Would you like to work on it? |
Yes, I can. I'll try to do PR on this weekend. |
Apply PathFilterIterator only to directory root if path provided as non regex
We are seeing this bug too in Bref (brefphp/bref#51). #28410 fixes it but is considered a BC break: is it really considered a break if the behavior it's fixing is broken? By "broken" I mean it's not respecting the original contract which is:
(https://api.symfony.com/4.1/Symfony/Component/Finder/Finder.html#method_exclude) |
|
I understand the whole argument about the behaviour of (for example) For example: I'm building a custom gettext string scanner for my company with the Console component. Based on old $paths = [
BASE_PATH.'/admin',
BASE_PATH.'/public',
'!admin/DontTranslate.php'
'!admin/excluded_folder'
]; I'm iterating the array and getting the paths starting with an exclamation as exclusions. This would be the function that lists all the files I want to be scanned, iterating through the files and folders, taking in consideration the exclusions: private function scanRecursively(array $items)
{
$results = [];
$exclusions = [];
foreach ($items as $key => $pattern) {
if ($pattern[0] === '!') {
$exclusions[] = substr($pattern, 1);
unset($items[$key]);
}
}
foreach ($items as $key => $pattern) {
$path = realpath($pattern);
// Si el elemento es una ruta a un fichero directamente, añadimos a resultados.
if ($path !== false && !is_dir($path)) {
$results[] = $path;
unset($items[$key]);
}
}
$finder = new Finder();
$finder->files()->in($items)->name('*.php')->name('*.js');
foreach ($exclusions as $exclusion) {
$finder->notPath($exclusion);
}
foreach ($finder as $file) {
$results[] = $file->getPathname();
}
return $results;
} The thing is: if I'm providing full paths to multiple inclusions, and relative paths for the exclusions ( Right now, I'm forced to write the array like this: $paths = [
BASE_PATH.'/admin',
BASE_PATH.'/public',
'!DontTranslate.php'
'!excluded_folder'
]; Which seems to work wonders, but if there is a |
The Symfony Finder component only allows excluding folders via relative paths, meaning we can only exclude the `database/migrations` folder if we exclude all folders named `migrations`. Instead we can skip including the entire `database` path and only include the known subfolders we want to format. See symfony/symfony#28158.
The Symfony Finder component only allows excluding folders via relative paths, meaning we can only exclude the `database/migrations` folder if we exclude all folders named `migrations`. Instead we can skip including the entire `database` path and only include the known subfolders we want to format. See symfony/symfony#28158.
I closed the linked PR, but I'm wondering: can't this be solved already by using a regexp? |
@nicolas-grekas : I think the Still I agree the current behavior is misleading. A workaround is to use Could it behave like |
would call this more a bug than a feature request assuming that only the first level is removed can lead to data loss if this would be used in a backup call.
where the directory structure is:
so
currently the "workaround" is using |
@c33s you should be able to use |
Thank you for this suggestion. |
Yep, I'm still here. |
Thank you for this suggestion. |
yes still looking for it |
Thank you for this suggestion. |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hello? This issue is about to be closed if nobody replies. |
This would be nice to have @carsonbot |
Thank you for this suggestion. |
@carsonbot yes |
Thank you for this suggestion. |
@carsonbot, yep. |
Anyone wants to work on a PR that implements this in a non-BC breaking way? (e.g. maybe using #28158 (comment) suggestion of doing root-only matches when the path is prefixed by Otherwise, I'm afraid we'll have to still close this as Stalled. This issue has not received any updates for the past 3 years, which makes me feel that unless someone invests time into this, we'll be at the same state 3 years from now. |
@wouterj please keep it open, i will have a look at it in my summer holidays (currently my workload is too high). |
Thanks @c33s. We'll leave this one open. |
This seems similar territory as #47431. |
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
PR with a proposed implementation is in #54752 if anyone feels like testing/reviewing. |
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
Fixes symfony#28158 Fixes symfony#47431 Related: symfony#26396 Related: symfony#9158 Related: symfony#28410
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:Rule
->exclude('data')
applies on any directory, so it excluding some nested folders: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
->exclude()
filter applying relatively to root folder, defined by->in()
method.The text was updated successfully, but these errors were encountered: