Skip to content
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

psalm checks for InvalidDocblock in ignoreFiles directory #4975

Closed
fluffycondor opened this issue Jan 11, 2021 · 8 comments
Closed

psalm checks for InvalidDocblock in ignoreFiles directory #4975

fluffycondor opened this issue Jan 11, 2021 · 8 comments

Comments

@fluffycondor
Copy link
Contributor

fluffycondor commented Jan 11, 2021

psalm 4.3.2, all plugins are disabled.

I got this:

ERROR: InvalidDocblock - vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:74:5 - Badly-formatted @param in docblock for Doctrine\ORM\EntityRepository::__construct (see https://psalm.dev/008)
    /**
     * Initializes a new <tt>EntityRepository</tt>.
     *
     * @psalm-param Mapping\ClassMetadata<T>
     */
    public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $class)

My project files in the config are defined as:

    <projectFiles>
        <directory name="src"/>
        <ignoreFiles>
            <directory name="vendor"/>
            <file name="src/Kernel.php"/>
        </ignoreFiles>
    </projectFiles>

Looks like some logic checks EntityRepository class for the reason that all custom repositories (that are belongs to <directory name="src"/>) are extended from this class.

@fluffycondor fluffycondor changed the title psalm 4.3.2 started to check for InvalidDocblock in ignoreFiles directory psalm checks for InvalidDocblock in ignoreFiles directory Jan 11, 2021
@orklah
Copy link
Collaborator

orklah commented Jan 11, 2021

This is expected behaviour for Psalm.

What is not expected however is syntax error in dependancies' phpdoc. And I'm actually to blame for this one as i pushed a wrong PR in doctrine/orm.

This was fixed here: doctrine/orm#8374 but I'm not sure this was released yet.

@weirdan
Copy link
Collaborator

weirdan commented Jan 12, 2021

Duplicate of #4265

@weirdan weirdan marked this as a duplicate of #4265 Jan 12, 2021
@weirdan weirdan closed this as completed Jan 12, 2021
@EtchAkhtar
Copy link

This is expected behaviour for Psalm.

What is not expected however is syntax error in dependancies' phpdoc. And I'm actually to blame for this one as i pushed a wrong PR in doctrine/orm.

This was fixed here: doctrine/orm#8374 but I'm not sure this was released yet.

@orklah hi .... why is it expected behaviour that psalm checks a file that is specifically being asked to be ignored? is there no way in the config to say "under no circumstances check files in these directories, even if a class in an unignored file references it (e.g. parent::construct)"

@orklah
Copy link
Collaborator

orklah commented Jan 13, 2021

@EtchAkhtar Basically Psalm has two modes when checking a file:

  • analyze it, which means it will enter each class/method and check statements
  • not analyze it, which means it will just look at signatures and phpdoc

Everything you include in projectFiles will be analyzed, except what you put in ignoreFiles. However, you can't stop Psalm to go check at your dependancies, because if it can't, it can't work at all.

For example, imagine you have a dependancy that have a method takesIntReturnBool. If you use it somewhere in your code, Psalm will have to check that you send int to it and it has to know you'll get bool from it. It can only do that by checking the file.

If Psalm were to add an option to absolutely not check a file, you'd just have big holes everywhere in your analysis and you wouldn't know it.

@EtchAkhtar
Copy link

@orklah thank you for the example, this make sense

@adamquaile
Copy link

I've been able to work around this using a baseline file, which I think is a valid use case for that ("I won't fix now, but want it recorded, and don't want my CI to break, or to have to disable checks").

https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#using-a-baseline-file

@orklah
Copy link
Collaborator

orklah commented Feb 3, 2021

Be warned that the issue emitted by Psalm means it wasn't able to parse the docblock. This means it will not be able to warn you if you sent a wrong type to this method or help you with the received type

@adamquaile
Copy link

Yeah, that makes sense. I don't know of any alternative, and I think this particular issue has been fixed, so whenever 2.8.2 is released (hopefully this quarter) we can delete it.

I don't think any of my code directly uses that constructor anyway, as Doctrine does that itself internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants