|
| 1 | +# Coding Standards |
| 2 | +Coding standards are a set of guidelines, best practices, programming styles and conventions that developers adhere to |
| 3 | +when writing source code for this project. |
| 4 | + |
| 5 | +> Info taken from this [article](https://www.lullabot.com/articles/how-enforce-drupal-coding-standards-git) from [Lullabot](https://www.lullabot.com) |
| 6 | +Provides set of libraries to easily setup code quality checks based on [GrumPHP](https://github.com/phpro/grumphp) for Drupal module/theme/profile. |
| 7 | + |
| 8 | +## Drupal |
| 9 | +This project impose Drupal code standard using GrumPHP. |
| 10 | + |
| 11 | +### Whitelist a code |
| 12 | +If you have an special situation where a peace of code need to be ignore: |
| 13 | +```php |
| 14 | +<?php |
| 15 | +// @codingStandardsIgnoreLine |
| 16 | +$honeyBadger = new HoneyBadger(); |
| 17 | + |
| 18 | +// Or on the same line. |
| 19 | +$honeyBadger = new HoneyBadger(); // @codingStandardsIgnoreLine |
| 20 | + |
| 21 | +// Or a code Block |
| 22 | +// @codingStandardsIgnoreStart |
| 23 | +$honeyBadger = new HoneyBadger(); |
| 24 | +if ($honeyBadger.cares()) throw new Exception(); |
| 25 | +// @codingStandardsIgnoreEnd |
| 26 | +``` |
| 27 | +or an entire file |
| 28 | +```php |
| 29 | +<?php |
| 30 | +// @codingStandardsIgnoreFile |
| 31 | +class HoneyBadger { |
| 32 | + public function cares() { return FALSE; } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### GrumPHP doesn't do anything? |
| 37 | +GrumPHP pre-commit script only checks your added/changed files for violations, not all the code in your project. |
| 38 | +Generally, this is a good thing, as you don’t want to fix unrelated code in your pull request. But if you do want to run |
| 39 | +a complete check of all the code in the repository or a specific directory, you can use your code editor to generate a |
| 40 | +report or one of these command-line tools: |
| 41 | +```bash |
| 42 | +php vendor/bin/grumphp run |
| 43 | +``` |
0 commit comments