Install Coder with composer:
composer global require drupal/coder
Custom setup using for Drupal Coding Standards.
Add symbolic path to support Drupal and DrupalPractice Standard:
$ ln -s ~/.composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/Drupal
$ ln -s ~/.composer/vendor/drupal/coder/coder_sniffer/DrupalPractice ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/DrupalPractice
If you're using bash, edit $HOME/.bashrc (or $HOME/.bash_profile).
alias drupalcs="~/.composer/vendor/bin/phpcs --colors --standard=~/.composer/vendor/drupal/coder/coder_sniffer/Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md"
Or if you added symbolic links:
alias drupalcs="~/.composer/vendor/bin/phpcs --colors --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md"
source .bashrc
Execution example:
$ drupalcs modules/custom/custom_crm
FILE: ...ww/docroot/modules/custom/custom_crm/src/CrmConfigUri.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
3 | ERROR | [x] There must be one blank line after the namespace
| | declaration
6 | ERROR | [x] Missing class doc comment
28 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Time: 157ms; Memory: 7.75Mb
References:
Comentarios