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
Latest Psalm release scan vendor when it should not and fails there #7332
Comments
As discussed in Slack, the basic psalm command runs fine without arguments. The error happens when running the command through composer with I believe this may be related to #7210 |
Yes it could be related to #7210. I assume If it is called the same way as in the composer script it shouldn't have worked before as well (there's multiple paths and it's not The rule is basically: if you supply any paths/files via the command line the |
I was told it's just the path. The command is the one in the composer command
Oh right, I forgot that. @reypm what is the goal to have the path in argument in your composer script? |
Ah now I get it yes, it's the output from the composer script, and I didn't read it correctly - it calls psalm multiple times but with just one argument. So now that I'm not confused anymore I can say for sure that it's because of #7210. The "../framework" is the So yes as @orklah said, it's best to run psalm without any arguments so the composer script would just be
Now if you have <directory name="../*/vendor"/> This would exclude all sibling vendor directories, because the glob *vendor just excludes the vendor directory in |
@orklah, @vstm the idea with the command and the path is to move into different directories. See for example the following project structure: my-app/
├─ .git/
├─ Dockerfiles/
├─ Folder1/
├─ framework/
│ ├─ config/
│ ├─ features/
│ ├─ src/
│ ├─ var/
│ ├─ vendor/
├─ Folder 2/
├─ .gitignore
├─ README.md First of all, I will start saying If I run just Can any of you think in a different way to achieve this? 🤔 |
Thank you for the explanation. It should be possible to do this with just the psalm.xml config. The question is where is your psalm.xml located in the project structure, is it also in the framework folder? All the paths in the projectFiles are relative to the psalm.xml, so that's why it's important where it is located. So if your psalm.xml is in the framework directory it actually should work like you would expect. I tried to replicate your structure and psalm scans also in the other directories (I have included the exact xml config in the output): ➜ framework ./vendor/bin/psalm --version
Psalm 4.18.0.0
➜ framework ./vendor/bin/psalm
Target PHP version: 7.4 (inferred from current PHP version)
Scanning files...
Analyzing files...
ERROR: UndefinedGlobalVariable - ../Folder1/Fail.php:1:6 - Cannot find referenced variable $fail in global scope (see https://psalm.dev/127)
?php $fail->fail();
ERROR: UndefinedGlobalVariable - ../Folder2/Fail.php:1:6 - Cannot find referenced variable $fail in global scope (see https://psalm.dev/127)
?php $fail->fail();
ERROR: UndefinedGlobalVariable - src/Fail.php:1:6 - Cannot find referenced variable $fail in global scope (see https://psalm.dev/127)
?php $fail->fail();
------------------------------
3 errors found
------------------------------
3 other issues found.
You can display them with --show-info=true
------------------------------
Checks took 0.01 seconds and used 4.939MB of memory
No files analyzed
Psalm was able to infer types for 0.0000% of the codebase
➜ framework cat psalm.xml
<?xml version="1.0"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" errorLevel="7" totallyTyped="true"
strictBinaryOperands="true" useDocblockPropertyTypes="true"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name=".." />
<ignoreFiles>
<directory name="../.git" />
<directory name="../Dockerfiles" />
<directory name="vendor" />
<directory name="features" />
<directory name="var" />
</ignoreFiles>
</projectFiles>
</psalm>
➜ framework tree -L 3 ../../my-app
../../my-app
├── Dockerfiles
├── Folder1
│ └── Fail.php
├── Folder2
│ └── Fail.php
├── framework
│ ├── composer.json
│ ├── composer.lock
│ ├── config
│ ├── features
│ │ └── Fail.php
│ ├── psalm.xml
│ ├── src
│ │ └── Fail.php
│ ├── var
│ │ └── Fail.php
│ └── vendor
│ ├── ... omitted
└── psalm.xml
|
@vstm thank you a lot, gonna give this a try and will see if it works then if everything is fine will close this issue. |
@vstm in my case seems not to be working ... :( I have exactly what you have and psalm seems to be scanning only what is inside root@3ff6e051f8c6:/var/www/framework# composer psalm
> ./vendor/bin/psalm
Target PHP version: 8.1 (inferred from composer.json)
Scanning files...
Analyzing files...
------------------------------
No errors found!
------------------------------
65 other issues found.
You can display them with --show-info=true
------------------------------
Checks took 0.01 seconds and used 12.380MB of memory
No files analyzed
Psalm was able to infer types for 90.8057% of the codebase any ideas in what could be wrong here? |
Oh, at the moment I have no idea. It seems that it doesn't even scan the framework folder now (It says "No files analyzed |
@vstm here it is ... <?xml version="1.0"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" errorLevel="7" totallyTyped="true"
strictBinaryOperands="true" useDocblockPropertyTypes="true"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name=".."/>
<ignoreFiles>
<directory name="vendor"/>
<directory name="var"/>
<directory name="features"/>
<file name="phpinsights.php"/>
<file name="rector.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin">
<containerXml>var/cache/dev/App_KernelDevDebugContainer.xml</containerXml>
</pluginClass>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<MethodSignatureMismatch errorLevel="suppress"/>
<UndefinedDocblockClass errorLevel="suppress"/>
<MissingFile errorLevel="suppress"/>
<UndefinedClass errorLevel="suppress"/>
<PluginIssue name="RepositoryStringShortcut" errorLevel="suppress" />
</issueHandlers>
</psalm> I executed it one more time and now seems to be working 🤔 I haven't made any other changes and/or updates. However I am not sure what directory is Psalm scanning or files, any way to know those? # composer psalm
> ./vendor/bin/psalm
Target PHP version: 8.1 (inferred from composer.json)
Scanning files...
Analyzing files...
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 60 / 82 (73%)
░░░░░░░░░░░░░░░░░░░░░░
------------------------------
No errors found!
------------------------------
65 other issues found.
You can display them with --show-info=true
------------------------------
Psalm can automatically fix 6 of these issues.
Run Psalm again with
--alter --issues=InvalidNullableReturnType,InvalidFalsableReturnType,MissingParamType --dry-run
to see what it can fix.
------------------------------
Checks took 5.08 seconds and used 237.624MB of memory
Psalm was able to infer types for 90.8057% of the codebase |
Hmm maybe it was a cache-issue. To find out if it actually works you can run psalm with <?php $fail->fail(); Psalm should find at least one issue with that. Otherwise you can use the $ composer psalm -- --no-cache --debug 2>&1 | grep Analyzing |
Thanks @vstm ! |
I have upgraded my Psalm to the latest 4.18 and now it scans the
vendor
directory when it should not as per thepsalm.xml
(see below) file configuration.Issues found:
The error reads as below:
Below is some helpful information to try to fix this in the case is a bug:
PHP Information:
# php -v PHP 8.1.1 (cli) (built: Dec 21 2021 03:37:39) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies with blackfire v1.72.0~linux-x64-non_zts81, https://blackfire.io, by Blackfire
psalm.xml
composer.json
The text was updated successfully, but these errors were encountered: