Drupal Code Linting with Sublime Text, PHPStorm and VSCode

Publié le 05/02/2018 | #drupal , #php

Using ZSH?

Create a .zprofile with this: export PATH=$HOME/.composer/vendor/bin:$PATH

Getting CodeSniffer and Drupal Coder

  • Install code sniffer v2.7 globally with composer (see this issue): composer global require squizlabs/php_codesniffer

  • Install drupal/coder globally with composer: composer global require drupal/coder

  • Register the Drupal and DrupalPractice Standard with PHPCS: phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

Sublime Text configuration

  • Get SublimeLinter using Package Control: + P Package Control: Install Package and then SublimeLinter

  • Get SublimeLinter-phpcs using Package Control: + P Package Control: Install Package and then SublimeLinter-phpcs

  • You can set the standard globally in your SublimeLinter Settings (Preferences > Package Settings > Sublime Linter > Settings) or per project in your .sublime-project file:

    "SublimeLinter": {
        "linters": {
            "phpcs": {
                "standard": "Drupal"

PHP Storm configuration

Official instructions here.

  • Under Preferences > Languages & Frameworks > PHP > Code Sniffer select “Local” for the phpcs script path and paste the exact path to your local installation: (on macOS it would like this: /Users/yourusername/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcs)

  • Open and check Preferences > Editor > Inspections > PHP Code Sniffer validation

  • From the right pane select the Coding standard drop-down list, choose “Custom” and click the Browse button

  • In the Custom Coding Standard dialog box that opens, specify the path to the root directory of your own coding standard in the Root directory, something like: /Users/yourusername/.composer/vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml

VSCode Configuration

  • Install the phpcs extension

  • In the preferences search for “phpcs” and then set the standard to “Drupal”