Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active September 18, 2021 18:39
Show Gist options
  • Save jrobinsonc/e09f42e4f57deb3acbf2c6746944f6d1 to your computer and use it in GitHub Desktop.
Save jrobinsonc/e09f42e4f57deb3acbf2c6746944f6d1 to your computer and use it in GitHub Desktop.
VSCode task problemMatcher for Psalm

Use Psalm to check your PHP files in VSCode

First, install the composer package: composer require --dev vimeo/psalm.

Then, add this code to your .vscode/tasks.json:

{
      "label": "Psalm",
      "detail": "Run Psalm",
      "type": "process",
      "problemMatcher": {
        "owner": "php",
        "fileLocation": ["relative", "${workspaceFolder}"],
        "severity": "warning",
        "pattern": {
          "regexp": "^(ERROR):\\s([^\\s]+)\\s-\\s([^:]+):([0-9]+):([0-9]+)\\s-\\s(.+)$",
          "file": 3,
          "line": 4,
          "column": 5,
          "severity": 1,
          "message": 6,
          "code": 2
        }
      },
      "command": "vendor/bin/psalm",
      "args": [
        "${file}"
      ],
      "presentation": {
        "reveal": "never"
      }
    }

After that you should be able to use the task to lint your PHP files

If you prefer PHPStan check here:
https://gist.github.com/jrobinsonc/d1672d16bdfd930b7e43ea19f40fd1d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment