-
-
Notifications
You must be signed in to change notification settings - Fork 490
Setting up WordPressCS to work in Sublime Text
jrfnl edited this page Aug 20, 2023
·
1 revision
As of writing this, the only working approach is this, which uses sublime-phpcs
. The article linked has a full, step by step instruction with possible issue resolutions as well.
Install the sublime-phpcs package, then use the "Switch coding standard" command in the Command Palette to switch between coding standards.
sublime-phpcs is insanely powerful, but if you'd prefer automatic linting, SublimeLinter-phpcs can do that.
- Install PHP Sniffer and WordPress Coding Standards per the installation instructions in the readme.
- Use Package Control to search for and install SublimeLinter then SublimeLinter-phpcs.
- From the command palette, select
Preferences: SublimeLinter Settings - User
and changeuser.linters.phpcs.standard
to the phpcs standard of your choice (e.g.WordPress
, etc.). - If setting
standard
doesn't work, try settinguser.linters.phpcs.args
to"--standard=WordPress-Core"
- You can also specify the standard to:
"standard": "$folder/phpcs.xml.dist"
. That way the linter will check the root folder of your project for aphpcs.xml.dist
file and read the location and usage of a standard from the file. This is useful if you are using custom ruleset.
- You can specify multiple standards, show violation codes, include runtime args for something like PHPCompatibility, and choose which directories to ignore:
// SublimeLinter Settings - User
{
"linters": {
"phpcs": {
"args": "--standard=WordPress-Extra,WordPress-Docs,PHPCompatibilityWP --runtime-set testVersion 7.2- -s",
"excludes": "vendor/"
}
}
}
- You may need to restart Sublime for these settings to take effect. Error messages appear in the bottom of the editor.
You can also choose to Show All Errors (from the Command Pallette) - when you select a line, the list scrolls to the correct line: