You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Excluded paths are traversed – problem with infinite loops of symlinks #9158
We have a monorepo with multiple projects and use PHPStan to lint the entire repository. However, we recently switched to Yarn with pnpm linker, which creates many symlinks that create a deeply nested structure and possibly loops (e.g. node_modules/.store/LIB-A/node_modules/LIB-B points to node_modules/.store/LIB-B and node_modules/.store/LIB-B/node_modules/LIB-A points to node_modules/.store/LIB-A). It looks like the RecursiveDirectoryIterator that is used by symfony/finder or maybe the OS itself has some kind of limit (maybe the maximal length of the path?), so it does not cause infinite loops but significantly slows down PHPStan.
We attempted to solve this issue by excluding certain paths, such as admin/node_modules/*. However, we noticed that PHPStan still traverses these excluded paths.
If it was possible for the iterator to detect we’re in infinite loop, and cut that branch away, that would be best. Because people wouldn’t have to configure anything and it’d just work.
I try to prepare example how to reproduce this issue. I realised that phpstan deal with cycling paths better than expected.
What I have found:
symlink is visited only 32 times - no infinite loop
excludePaths statement prevent visiting symlink.
Excluding problematic path looks like good enough solution.
We have php source code under more directories not only in one src root directory. So I cannot use excludePaths: src/*/node_modules. If you are in same situation, you can try to exclude node_modules with: excludePaths: */node_modules.
In my case I cannot use */node_modules. Path starting with * emits errors in our CI where we use yq to changing config file and strings starting with * has special meaning in yaml. (it's not PHPStan issue, it's yaml)
So final solution for our monorepo project was special file with shared excludedPaths.
Activity
mergeable commentedon Apr 6, 2023
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
ondrejmirtes commentedon Apr 7, 2023
I'm afraid the exclusion mechanics of Symfony Finder (https://symfony.com/doc/current/components/finder.html) are different from PHPStan's
excludePathsso I'm not sure how we could easily fix this. Feel free to look into it :) Thanks.maryo commentedon Apr 19, 2023
Symfony has
->notPath(which acceptsstring|string[] $patterns A pattern (a regexp or a string) or an array of patternshttps://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Finder/Finder.php#L278
https://github.com/phpstan/phpstan-src/blob/1.10.13/src/File/FileExcluder.php#L22
The easiest solution would be to pass there
$literalAnalyseExcludes.Or even the
fnmatchpattern could be converted to regex.Or if PHPStan switched to gitignore pattern (which has more features like
**) then Symfony has a method that converts it to regex.https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Finder/Gitignore.php#L27
Do you want any of this? Which solution would you prefer?
ondrejmirtes commentedon Apr 19, 2023
I prefer this problem first be reproduced in https://github.com/phpstan/phpstan/blob/1.11.x/.github/workflows/other-tests.yml and then doing any solution that makes it pass 😊
If it was possible for the iterator to detect we’re in infinite loop, and cut that branch away, that would be best. Because people wouldn’t have to configure anything and it’d just work.
integer commentedon Mar 5, 2024
I try to prepare example how to reproduce this issue. I realised that phpstan deal with cycling paths better than expected.
What I have found:
excludePathsstatement prevent visiting symlink.Excluding problematic path looks like good enough solution.
We have php source code under more directories not only in one
srcroot directory. So I cannot useexcludePaths: src/*/node_modules. If you are in same situation, you can try to exclude node_modules with:excludePaths: */node_modules.In my case I cannot use
*/node_modules. Path starting with*emits errors in our CI where we useyqto changing config file and strings starting with*has special meaning in yaml. (it's not PHPStan issue, it's yaml)So final solution for our monorepo project was special file with shared excludedPaths.
Maybe it can help to someone else.