Sunday 19 November 2017

Installing Code Sniffer with Drupal Coding Standard on Windows

Below are the steps required for successful installation of PHP CoderSniffer with Drupal coding standard on Windows using gitbash.

1. Open you gitbash and check for composer path:
$ which composer
2. If you get composer not found or similar, follow Composer's installation instructions.

3. Install latest stable release of Coder Globally:$ composer global require drupal/coder

On Windows, the path may look like C:/Users/<WindowsUsername>/AppData/Roaming/Composer.

4. Below command will show you the installed location:$ composer global show -P

5. Make your coder version the preferred source:$ composer global update drupal/coder --prefer-source

6. On Windows, To have phpcs and phpcbf globally update your ~/.bashrc file to include:$ export PATH="$HOME/AppData/Roaming/Composer/vendor/bin:$PATH"

7. Install Drupal coding standard through plugin:$ composer global require dealerdirect/phpcodesniffer-composer-installer

8. Manually set installed path:$ phpcs --config-set installed_pathsC:/Users/<WindowsUsername>/AppData/Roaming/Composer/vendor/drupal/coder/coder_sniffer

9. Verify registered standard:$ phpcs -i

Now you should be able to use phpcs and phpcbf commands on your module files.

e.g. $ phpcs --standard=Drupal <my module path>/*

Auto correct coding standard issues found by the above command:

$ phpcbf --standard=Drupal <my module path>/*

Please remember that manually review your code after auto correction to avoid any unnecessary changes introduce by phpcbf itself.

No comments :

Post a Comment