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

Suppress UnusedClass/PossiblyUnusedMethod on well-known classes/methods of fresh Laravel/Lumen projects #183

Merged
merged 4 commits into from
Jul 13, 2021

Conversation

caugner
Copy link
Contributor

@caugner caugner commented Jul 13, 2021

Fixes #53.

@caugner caugner changed the title Fix UnusedClass on fresh Laravel/Lumen projects Suppress UnusedClass/PossiblyUnusedMethod on well-known classes/methods of fresh Laravel/Lumen projects Jul 13, 2021
@caugner caugner marked this pull request as ready for review July 13, 2021 09:52
* @var array<string, list<class-string>>
*/
private const BY_CLASS = [
'UnusedClass' => [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if these are still emitted if the bootstrap/app.php file is analyzed? Thinking out loud..

Copy link
Contributor Author

@caugner caugner Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, bootstrap/app.php does use App\Console\Kernel, App\Exceptions\Handler and App\Http\Kernel. And some of the other classes are used in config/app.php.

So maybe it is worth adding those directories to the tests/(laravel|lumen)-test-psalm.xml configs. 🤔

In my project, I have configured <projectFiles> likes this, probably due to too many errors (and some of this could explain some of the weird errors I have experienced):

    <projectFiles>
        <directory name="."/>
        <ignoreFiles allowMissingFiles="true">
            <directory name="app/Http/Middleware"/>
            <directory name="bootstrap/cache"/>
            <directory name="cache"/>
            <directory name="config"/>
            <directory name="database"/>
            <directory name="node_modules"/>
            <directory name="routes"/>
            <directory name="storage"/>
            <directory name="tests"/>
            <directory name="vendor"/>
            <directory name="vendor-bin"/>
            <file name="bootstrap/app.php"/>
            <file name="public/index.php"/>
            <file name="server.php"/>
        </ignoreFiles>
    </projectFiles>

edit: Ideally, we would support as much files as possible, and make a recommendation in the README.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, didn't view that as a blocker for this PR, but something we should consider!

@mr-feek mr-feek added the enhancement New feature or request label Jul 13, 2021
@mr-feek mr-feek merged commit c032e4e into psalm:master Jul 13, 2021
@mr-feek
Copy link
Collaborator

mr-feek commented Jul 13, 2021

This is awesome! Thanks a lot for your help

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

Successfully merging this pull request may close these issues.

This plugin ought to suppress PossiblyUnusedClass/Method on common Laravel idoms
2 participants