Making PHP Code Sniffer plugin work in Sublime Text 3

I’ve installed php Code Sniffer Sublime Text 3 plugin today and, aside for the installation of accessory tools the plugin will need to work its over-zealous finger-pointing-at-bad-code magic I’ve run into a problem about its setting I’ve never run into before for any other Sublime Text plugin.

Easy part

Installing the plugin itself can be done via Package Control searching for “Phpcs”.
After that a little OS fiddling will be required to install

  1. PHP Code Sniffer
  2. PHP Mess Detector
  3. eventually PHP Coding Standards Fixer

and I will gladly leave that part behind. It’s trivial anyway.


After all that is done launching the PHP Code Sniffer: sniff this file command will be of no visible effect. Simply put the plugin needs to know the paths to launch the just installed CLI tools.
As detailed the plugin site some configuration is required. After browsing Sublime Text bar

Phpcs settings
Phpcs settings

I end up with the plugin configuration file but it seems like I can’t edit it.
Missing file...
Missing file…

Easy fix

The fix is as easy as simply creating the missing Phpcs folder and trying to edit the file again.

$ mkdir ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Phpcs

This time editing the settings file will work, having an actual real place to write its contents, and launching PHP Code Sniffer: sniff this file will light your .php file like a Christmas tree pointing out all your frowned-upon coding practices.

Unpolite finger-pointing
I hate it.

7 thoughts on “Making PHP Code Sniffer plugin work in Sublime Text 3

  1. I’ve been able to install the package Phpcs for sublime, and add through pear PHP-CS, MD, but it doesn’t seems so trivial to install Fixer. Not sure what to do with the .phar file. I can see that I need to add its path to the user settings, similar to phpcs and phpmd, but is that the path to the .phar… or do I unpack it. Also, have you ever used Scheck? It appears to be the fourth addon for Phpcs package for sublime, it’s even more confusing to install it seems.

    1. Phar files are executable so so not unpack it and leave it like that. Maybe move it/link it in the bin folder of your machine. As for Scheck I have never used it and cannot help you there.

  2. Just a note: you don’t need the ‘Easy Fix’.

    You SHOULD not edit the Default setting files. Neither for Sublime settings or any other plugin.
    To customise just some settings you should edit the “Settings – User”, the selection just under the one that is highlighted into the first screenshot of this article.
    The “Settings – Default” should be used just as reference for the available variables, making a copy in the “Settings – User” (as valid JSON) when someone needs to customise their value.

    I just wanted to clarify it, otherwise the suggestion could be misleading on how Sublime works; while it provides a clean way to deal with settings 😉

    1. Absolutely right, thanks for pointing it out.

      The user settings are the ones that should be edited, as you rightly say, and not the default ones that would get overwritten on each update. I cannot edit the misleading image to reflect that: it’s a mistake made in a rush and will be there as “no-no” example.

I appreciate your input