moxio / captainhook-psalm
Captain Hook Plugin to check for newly introduced Psalm errors
Installs: 31 469
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- ext-dom: *
- captainhook/captainhook: ^4.4 || ^5.0
- sebastianfeldmann/cli: ^3.0
- sebastianfeldmann/git: ^2.2 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-29 06:41:39 UTC
README
moxio/captainhook-psalm
This project is a plugin for CaptainHook to check your staged PHP files for errors using Psalm. The commit is blocked when one or more errors is detected in any of the staged PHP files.
Installation
Install as a development dependency using composer:
$ composer require --dev moxio/captainhook-psalm
Usage
Add Psalm error checking as a pre-commit
-hook to your captainhook.json
configuration file:
{ "pre-commit": { "enabled": true, "actions": [ { "action": "\\Moxio\\CaptainHook\\Psalm\\PsalmCheckAction" } ] } }
The check is only run when committing changes to PHP files. It will thus not detect pre-existing errors in PHP files which are not staged.
The action expects Psalm to be installed as a local Composer package (i.e. available
at vendor/vimeo/psalm
).
Conditional usage
If you want to perform Psalm-error checks only when Psalm is installed (i.e. available at
vendor/vimeo/psalm
), you can add a corresponding condition to the action:
{ "pre-commit": { "enabled": true, "actions": [ { "action": "\\Moxio\\CaptainHook\\Psalm\\PsalmCheckAction", "conditions": [ { "exec": "\\Moxio\\CaptainHook\\Psalm\\Condition\\PsalmInstalled" } ] } ] } }
This may be useful in scenarios where you have a shared CaptainHook configuration file that is included both in projects that use Psalm and projects that don't. If Psalm is installed, the action is run. In projects without Psalm, the validation is skipped.
Influence of projectFiles
in psalm.xml
If this plugin detects a psalm.xml
configuration file, this plugin will try to use the
projectFiles
configured in that file to filter the files checked by Psalm. This is done
on a best-effort basis: not all constructs possible within projectFiles
are supported,
but simple directories and files (along with ignoreFiles
) should work fine. If you
encounter a situation where files aren't properly filtered, feel free to send a PR.
Versioning
This project adheres to Semantic Versioning.
Contributing
Contributions to this project are welcome. Please make sure that your code follows the PSR-12 extended coding style.
License
This project is released under the MIT license.