Skip to content

Setting up WordPressCS to work in Sublime Text

jrfnl edited this page Aug 20, 2023 · 1 revision

Functioning in 2023

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.

sublime-phpcs package

Install the sublime-phpcs package, then use the "Switch coding standard" command in the Command Palette to switch between coding standards.

SublimeLinter-phpcs

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 change user.linters.phpcs.standard to the phpcs standard of your choice (e.g. WordPress, etc.).
  • If setting standard doesn't work, try setting user.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 a phpcs.xml.dist file and read the location and usage of a standard from the file. This is useful if you are using custom ruleset.

SublimeLinter-phpcs user settings

  • 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.

SublimeLinter-phpcs linting

SublimeLinter-phpcs error

You can also choose to Show All Errors (from the Command Pallette) - when you select a line, the list scrolls to the correct line:

Screenshot showing all errors in Sublime Text 3