vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 659 forks source link

Psalm is scanning its own temp folder that located outside the project directory, causes yielding errors that was suppressed in config #6319

Open fluffycondor opened 3 years ago

fluffycondor commented 3 years ago

Psalm 4.8.1@f73f2299dbc59a3e6c4d66cff4605176e728ee69 Psalm for some reason is scanning its own temp folder that located outside the project directory.

vendor/bin/psalm 
Scanning files...
Analyzing files...

ERROR: MissingConstructor - ../../../../tmp/Psalmtemp_folder1430/src/DTO/RequestByDepotId.php:12:16 - App\DTO\RequestByDepotId has an uninitialized property App\DTO\RequestByDepotId::$depotId, but no constructor (see https://psalm.dev/073)
    public int $depotId;

------------------------------
1 errors found
------------------------------

Checks took 0.09 seconds and used 14.947MB of memory
No files analyzed
Psalm was able to infer types for 99.9655% of the codebase

In the project itself this kind of errors are suppressed:

    <projectFiles>
        <directory name="src"/>
        <ignoreFiles>
            <directory name="vendor"/>
            <file name="src/Kernel.php"/>
        </ignoreFiles>
    </projectFiles>
    <issueHandlers>
        <MissingConstructor>
            <errorLevel type="suppress">
                <directory name="src/DTO"/>
            </errorLevel>
        </MissingConstructor>
    </issueHandlers>

This error appears kinda inconsistent, but if it appears only way to get rid of it is to delete psalm temp folder (Psalmtemp_folder1430 in this case).

psalm-github-bot[bot] commented 3 years ago

Hey @fluffycondor, can you reproduce the issue on https://psalm.dev ?

orklah commented 3 years ago

Can you post the entire psalm.xml file please?

fluffycondor commented 3 years ago
<?xml version="1.0"?>
<psalm
    errorLevel="1"
    resolveFromConfigFile="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="src"/>
        <ignoreFiles>
            <directory name="vendor"/>
            <file name="src/Kernel.php"/>
        </ignoreFiles>
    </projectFiles>
    <issueHandlers>
        <MissingConstructor>
            <errorLevel type="suppress">
                <directory name="src/DTO"/>
            </errorLevel>
        </MissingConstructor>
    </issueHandlers>
    <forbiddenFunctions>
        <function name="dd"/>
        <function name="dump"/>
    </forbiddenFunctions>
    <plugins>
        <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
        <pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
    </plugins>
</psalm>
weirdan commented 3 years ago

Psalm is outputting cached errors here - I've seen it when I manually scanned a file outside the projectFiles, and then re-run Psalm with no files specified on the command line.

Psalmtemp_folder is not a Psalm's folder though - it's created by PHPStorm Psalm plugin.

Workaround is to clear the cache: psalm --clear-cache.

weirdan commented 3 years ago

We should probably filter out cached errors for files that are not on the list of files for the current run.

orklah commented 3 years ago

IMHO, we should not even try to use the same cache if the command line or xml config has changed between two calls.

weirdan commented 3 years ago

Well, I would like cache built with $ psalm to be used when I run $ psalm path/to/file.php, if path/to/file.php is in project files. Otherwise lint-on-save is going to be quite a bit slower.

orklah commented 3 years ago

@weirdan a few days ago, I observed that doctrine's plugin can't find entities when the repository isn't part of the analysis. So when launched on a single file, it can throw UndefinedClass that stays in cache when running the full analysis. Not sure if Psalm core can react the same way though...