Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active September 18, 2021 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrobinsonc/d1672d16bdfd930b7e43ea19f40fd1d3 to your computer and use it in GitHub Desktop.
Save jrobinsonc/d1672d16bdfd930b7e43ea19f40fd1d3 to your computer and use it in GitHub Desktop.
VSCode task problemMatcher for PHPStan

Use PHPStan to check your PHP files in VSCode

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

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

{
  "label": "PhpStan",
  "detail": "Run PhpStan",
  "type": "process",
  "problemMatcher": {
    "owner": "php",
    "fileLocation": ["absolute"],
    "severity": "warning",
    "pattern": {
      "regexp": "^(.+):(\\d+):(.+)$",
      "file": 1,
      "location": 2,
      "message": 3
    }
  },
  "command": "vendor/bin/phpstan",
  "args": [
    "analyse",
    "--no-progress",
    "--error-format=raw",
    "${file}"
  ],
  "presentation": {
    "reveal": "never"
  }
}

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

If you prefer PSalm check here:
https://gist.github.com/jrobinsonc/e09f42e4f57deb3acbf2c6746944f6d1

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