Chris@14: # Coder Chris@14: Chris@18: [![Build Status](https://travis-ci.org/pfrenssen/coder.svg?branch=8.x-3.x)](https://travis-ci.org/pfrenssen/coder) Chris@14: Chris@14: Coder is a library for automated Drupal code reviews and coding standard fixes. It Chris@14: defines rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) Chris@14: Chris@14: Built-in support for: Chris@14: - "Drupal": Coding Standards https://www.drupal.org/coding-standards Chris@14: - "DrupalPractice": Best practices for Drupal module development Chris@14: Chris@14: Online documentation: https://www.drupal.org/node/1419980 Chris@14: Chris@14: Note that Javascript support has been removed. To check and fix Javascript files Chris@14: please use [ESLint](http://eslint.org/) and see the Chris@14: [Drupal ESLint](https://www.drupal.org/node/1955232) documentation. Chris@14: Chris@14: Chris@14: ## Installation Chris@14: Chris@14: First, make sure Composer is installed correctly: Chris@17: Chris@17: which composer Chris@14: Chris@14: If you get composer not found or similar, follow Composer's installation Chris@14: instructions. Chris@14: Chris@18: Install Coder (8.x-3.x) in your global Composer directory in your home directory Chris@17: (`~/.composer`): Chris@14: Chris@17: composer global require drupal/coder Chris@17: Chris@17: To make the `phpcs` and `phpcbf` commands available globally, add the Composer Chris@17: bin path to your `$PATH` variable in `~/.profile`, `~/.bashrc` or `~/.zshrc`: Chris@17: Chris@17: export PATH="$PATH:$HOME/.composer/vendor/bin" Chris@14: Chris@14: Register the Drupal and DrupalPractice Standard with PHPCS: Chris@17: Chris@17: phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer Chris@17: Chris@17: Chris@17: ### Composer Installer Plugins Chris@17: Chris@17: The Coder package (>= 8.2.11) now works with Composer Installer Plugins, Chris@17: that find and register standards whenever packages are installed or updated. Chris@17: To use such a plugin within your project, follow these steps. Chris@17: Chris@17: composer require --dev dealerdirect/phpcodesniffer-composer-installer Chris@17: composer require --dev drupal/coder Chris@17: Chris@17: Now, you will see Drupal and DrupalPractice listed in the available PHP Chris@17: CodeSniffer standards. Chris@17: Chris@17: vendor/bin/phpcs -i Chris@17: Chris@17: The same can be done for a Composer global installation. Chris@17: Chris@17: composer global require dealerdirect/phpcodesniffer-composer-installer Chris@17: composer global require drupal/coder Chris@14: Chris@14: Chris@14: ## Usage Chris@14: Chris@14: Check Drupal coding standards Chris@17: Chris@17: phpcs --standard=Drupal /file/to/drupal/example_module Chris@14: Chris@14: Check Drupal best practices Chris@17: Chris@17: phpcs --standard=DrupalPractice /file/to/drupal/example_module Chris@14: Chris@14: Automatically fix coding standards Chris@17: Chris@17: phpcbf --standard=Drupal /file/to/drupal/example_module Chris@14: Chris@14: Chris@14: ## Working with Editors Chris@14: Chris@14: Drupal Code Sniffer can be used with various editors. Chris@14: Chris@14: Editors: Chris@14: Chris@18: - [Atom](https://www.drupal.org/node/1419996) Chris@17: - [Eclipse](https://www.drupal.org/node/1420004) Chris@17: - [Komodo](https://www.drupal.org/node/1419996) Chris@17: - [Netbeans](https://www.drupal.org/node/1420008) Chris@17: - [PhpStorm](https://www.jetbrains.com/help/phpstorm/php-code-sniffer.html) Chris@17: - [Sublime Text](https://www.drupal.org/node/1419996) Chris@17: - [Vim](https://www.drupal.org/node/1419996) Chris@18: - [Visual Studio Code (VSCode)](https://www.drupal.org/node/1419996) Chris@14: Chris@14: Chris@14: ## Automated Testing (PHPUnit + PHPCS) Chris@14: Chris@14: Coder Sniffer comes with a PHPUnit test suite to make sure the sniffs work correctly. Chris@14: Use Composer to install the dependencies: Chris@14: Chris@17: composer install Chris@14: Chris@14: Then execute the tests: Chris@17: Chris@17: ./vendor/bin/phpunit Chris@14: Chris@14: Then execute the coding standards checker on Coder itself: Chris@17: Chris@17: ./vendor/bin/phpcs Chris@14: Chris@14: Chris@14: ## Contributing Chris@14: Chris@14: 1. Make sure an issue exists at https://www.drupal.org/project/issues/coder Chris@18: 2. Create a [Pull Request](https://help.github.com/articles/using-pull-requests/) against https://github.com/pfrenssen/coder Chris@14: 3. Post a link to the pull request to the issue on drupal.org and set the issue to Chris@14: "needs review" Chris@14: Chris@14: Thank you! Chris@14: Chris@14: Chris@14: ## Maintainers Chris@18: Chris@18: - Pieter Frenssen, https://www.drupal.org/u/pfrenssen Chris@18: - Michael Welford, https://www.drupal.org/u/mikejw Chris@18: - Klaus Purer, https://www.drupal.org/u/klausi Chris@14: Chris@14: Chris@14: ## Credits Chris@14: Chris@14: Greg Sherwood and Squiz Pty Ltd, many sniffs are modified copies of their original Chris@14: work on [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer).