Setting up PHPCS in Sublime Text 3

Install the sublime-linter plugin and the sublime-linter-phpcs plugin through the Sublime Text package manager. This article assumes that you have already installed PHPCS globally on your machine, if not, follow the instructions on the PHPCS github page. Or checkout my article on Setting up WordPress Coding Standards (WPCS) Globally.

Once both plugins are installed go to Sublime Text > Preferences > Package Settings > SublimeLinter > Settings. These instuctions are assuming you’re running macOS.

In your settings add the following configurations. These settings assume that you will have your phpcs.xml file at the root of you project when opened in Sublime Text. You’ll also want to tell sublime-linter-phpcs where your .composer/vendor/bin directory is located under the “paths” section as seen below.

{
    "linters": {
        "phpcs": {
            "args": "--standard='${folder}/phpcs.xml'",
            "styles": [
                 {
                     "icon": "triangle"
                 }
            ]
        }
    },
    "paths": {
        "linux": [],
        "osx": [
            "~/.composer/vendor/bin"
        ],
        "windows": []
    }
}

When you open your project in Sublime Text you will be able to see any PHPCS errors highlighted. Optionally, you can open the Sublime Text console by clicking the button in the bottom left of the Sublime Text editor and clicking “Output: SublimeLinter”. This will display a list of all the PHPCS errors/warnings in a list for all open files.

Output: SublimeLinter