If you’re rocking VS Code and would like to automate PHPCS checking from within the editor, look no further.
Not installed PHPCS yet? Check out my guide first. Once that’s done, thankfully, the process to do this is quite simple…
- Click the Extensions icon in the left sidebar (or head into the toolbar and find it) and search for
phpcs
. At the time of writing this there were 2 available, but one was deprecated due to it not being maintained – you need the other one. - Install the extension.
- Open up Command Palette and search for
Preferences: Open User Settings (JSON)
- This will open up
settings.json
and show any existing user settings. - Add the following setting between the open and close braces…
"phpcs.standard": "{your standard(s)}",
If this is added after the final settings, make sure the penultimate one has a comma at the end.{your standard(s)}
is the name of your standard, or standards.
So my total file looks like this…
{
"workbench.colorTheme": "Default Dark Modern",
"php.validate.executablePath": "",
"phpcs.standard": "WordPress-Extra,WordPress-Docs,WordPress-VIP-Go",
}
- A full list of PHPCS parameters can be found on the extensions page and these can be added in the above config file.
And that’s it. To view your PHPCS output, make sure to open the Debug Console with the PROBLEMS tab active.
Talk to me!