How to add PHPCS checking to Sublime Text

monitor showing Java programming

If you’re rocking a shiny in stall of PHPCS and want to integrate it into Sublime Text then, thankfully, the process is relatively straightforward…

  1. Make sure you have PHP Code Sniffer installed as a package.
  2. Then head to Settings -> Package Settings -> PHP Code Sniffer -> Settings – User to configure any settings. You can find a full list here.

Technically, that’s all there is to it.

However, to get you started here’s a copy of my configuration…

	// --> Plugin <--

	// Which filetypes do you want the plugin to execute for?
	"extensions_to_execute": ["php"],

	// Do you want the code sniffer plugin to run on file save for php files?
	"phpcs_execute_on_save": true,

	// Do you want the errors to be displayed in quick_panel on save?
	"phpcs_show_errors_on_save": true,

	// Do you want the errors to be displayed in the quick panel?
	"phpcs_show_quick_panel": true,

	// ---> PHP_CodeSniffer <--

	// Do you want the PHPCS checker to run?
	"phpcs_sniffer_run": true,

	// Do you want the command to execute on save?
	"phpcs_command_on_save": true,

	// Path to phpcs
	"phpcs_executable_path": "/Users/davidartiss/.composer/vendor/bin/phpcs",

	// This is the extra information you want to pass to the phpcs command. 

	"phpcs_additional_args": {
	    "--standard": "WordPress-Extra,WordPress-Docs,WordPress-VIP-Go,PHPCompatibility",
	    "-w": ""

In this case, I’m rocking a particular settings of PHPCS sniffs (see the last line), only check upon save and output everything to the quick panel, which drops down from the top when there’s any output. Oh, and it’s designed to (not surprisingly) only scan .php extensions.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: