Skip to content

Instantly share code, notes, and snippets.

@sadanandkenganal
Last active May 18, 2016 09:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadanandkenganal/9c14598fbec55bd8caec to your computer and use it in GitHub Desktop.
Save sadanandkenganal/9c14598fbec55bd8caec to your computer and use it in GitHub Desktop.
Detects violations of a defined set of coding standards. It works with Drupal 6, 7, or 8.

Detects violations of a defined set of coding standards. It works with Drupal 6, 7, or 8.

PHP_CodeSniffer is a library that tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It works with Drupal 6, 7, or 8.

Coder contains "sniffs" for PHP CodeSniffer. These "sniffs" tell PHP CodeSniffer whether code meets Drupal coding standards or not.

Steps

1.First, make sure Composer is installed correctly:

 $ which composer

If you get composer not found or similar, follow Composer's installation instructions.

2.Install Coder (8.x-2.x) in your global Composer directory in your home directory (~/.composer):

$ composer global require drupal/coder

3.To make the phpcs and phpcbf commands available globally,

 nano ~/.bash_profile

4.Add export PATH="$PATH:$HOME/.composer/vendor/bin in the end and save.

5.Register the Drupal and DrupalPractice Standard with PHPCS:

$ phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

6.Open nano ~/.bash_profile and add following lines.

alias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"

alias drupalcsfix="phpcbf --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"

7.Run source ~/.bash_profile

8.Now you can use the alias like this:

$ drupalcs sites/all/modules/mymodule

$ drupalcsfix sites/all/modules/mymodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment