2017 © Pedro Peláez
 

library drupal-coding-standards

Creates a pre-push git hook that checks the Drupal coding standards.

image

drupal-standards/drupal-coding-standards

Creates a pre-push git hook that checks the Drupal coding standards.

  • Tuesday, November 17, 2015
  • by danielpopdan
  • Repository
  • 1 Watchers
  • 2 Stars
  • 403 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

About

This is a git pre-push hook intended to help Drupal developers to keep the code base clean by performing a scan with Drupal Coder whenever new code is pushed to the repository. When any coding standards violations are present the push is rejected, allowing the developer to fix the code before making it public., (*1)

To increase performance only the changed files are checked when new code is pushed to repository. Note that the full file will be checked, so if you didn't use this library from the beginning you can get coding violations from the past., (*2)

With this library you can make the code review phase more quickly, letting the reviewers just to concentrate on the logic of the project. If you don't want to use this anymore, you can easily delete the pre-push hook from .git/hooks/ directory. If you notice any issue, please let us know on GitHub issue page of the project., (*3)

Installation

Add Drupal Coding Standards to your composer.json:, (*4)

Option 1:, (*5)

composer require drupal-standards/drupal-coding-standards:master-dev

Option 2:, (*6)

composer.json, (*7)

{
  "require": {
    "drupal-standards/drupal-coding-standards": "master-dev"
  }
}

A post install scripts is needed to symlink the pre-push file of the library with the git pre-push file and to register the Drupal Coding Standards. Because of security issues, composer doesn't execute post install scripts of dependencies, so you will have to add this script to your composer.json. Please add the post install script to scripts/composer directory of your Drupal project root, in the post-install.sh file., (*8)

#!/bin/sh

# Symlink the git pre-push hook to its destination.
if [ ! -h ".git/hooks/pre-push" ] ; then
  ln -s "../../vendor/drupal-standards/drupal-coding-standards/pre-push" ".git/hooks/pre-push"
  vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
fi

After that you will have to make this script file executable:, (*9)

chmod u+x scripts/composer/post-install.sh

Please add the script to your composer.json file:, (*10)

"scripts": {
    "post-install-cmd": "scripts/composer/post-install.sh"
}

Now you can run composer install:, (*11)

composer install

Adding the Rule Set

The final step is to add the Drupal Code Sniffer Ruleset, because you probably have some files you don't want to be parsed., (*12)

The rule set contains two very important tags, and ., (*13)

With this tag you can exclude any file you want, by default all core files and features generated files are excluded, but you can add other files too, like a custom setting php, or you can totally exclude all files of a type, like CSS, because your css is generated by SAS., (*14)

For you can pass a name and a value which will be passed to Code Sniffer, for example:, (*15)

<arg name="standard" value="Drupal"/>

That will be passed as --standard=Drupal., (*16)

Every time you make a composer update this file will be overridden, so the best way to keep your configuration is to copy that file to your root directory of the Drupal project. The pre-push hook will check the file from your root every time., (*17)

The Versions

17/11 2015

8.0.x-dev

8.0.9999999.9999999-dev

Creates a pre-push git hook that checks the Drupal coding standards.

  Sources   Download

The Requires

 

drupal standards coding

17/11 2015

dev-master

9999999-dev

Creates a pre-push git hook that checks the Drupal coding standards.

  Sources   Download

The Requires

 

drupal standards coding

17/11 2015

7.0.x-dev

7.0.9999999.9999999-dev

Creates a pre-push git hook that checks the Drupal coding standards.

  Sources   Download

The Requires

 

drupal standards coding