Skip to content

Instantly share code, notes, and snippets.

@stmh
Last active August 29, 2015 14:14
Show Gist options
  • Save stmh/8995b7285731ffc373a4 to your computer and use it in GitHub Desktop.
Save stmh/8995b7285731ffc373a4 to your computer and use it in GitHub Desktop.
Sublime, code_sniffer and drupal

Sublime general settings

Open your user-preferences, and add/edit the following settings:

{
	"default_line_ending": "unix",
	"ensure_newline_at_eof_on_save": true,
	"fallback_encoding": "UTF-8",
        "rulers":
	[
		80
	],
	"shift_tab_unindent": true,
	"tab_size": 2,
	"translate_tabs_to_spaces": true,
	"trim_automatic_white_space": true,
	"trim_trailing_white_space_on_save": true,
	"use_tab_stops": true,
	"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"
}

Install prerequisites via brew

brew install php-code-sniffer
brew install php-cs-fixer
brew install phpmd

Install the codesniffer sublime-plugin via package-control (see readme from https://github.com/benmatselby/sublime-phpcs)

After that, check the package user-config. This is mine:

{
  "phpcs_executable_path": "/usr/local/bin/phpcs",
  "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",
  "phpmd_executable_path": "/usr/local/bin/phpmd",
  "phpmd_run": true,
  "phpcs_linter_run": true,
  "phpcs_show_quick_panel": false,
  "extensions_to_execute": ["install", "php", "module", "inc", "test"],
  "phpcs_additional_args": {
    "--standard": "Drupal",
    "-n": ""
  },
  "show_debug": true,
}

So, one last piece is missing. The drupal standards.

  • I download the coder-module from https://www.drupal.org/project/coder
  • Then I move the folder Drupal inside code_sniffer to the codesniffer-directory /usr/local/Cellar/php-code-sniffer/1.5.5/CodeSniffer/Standards (the version-number may differ, a symbolic link might work too)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment