annotate vendor/drupal/coder/README.md @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
rev   line source
Chris@4 1 # Coder
Chris@4 2
Chris@5 3 [![Build Status](https://travis-ci.org/pfrenssen/coder.svg?branch=8.x-3.x)](https://travis-ci.org/pfrenssen/coder)
Chris@4 4
Chris@4 5 Coder is a library for automated Drupal code reviews and coding standard fixes. It
Chris@4 6 defines rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
Chris@4 7
Chris@4 8 Built-in support for:
Chris@4 9 - "Drupal": Coding Standards https://www.drupal.org/coding-standards
Chris@4 10 - "DrupalPractice": Best practices for Drupal module development
Chris@4 11
Chris@4 12 Online documentation: https://www.drupal.org/node/1419980
Chris@4 13
Chris@4 14 Note that Javascript support has been removed. To check and fix Javascript files
Chris@4 15 please use [ESLint](http://eslint.org/) and see the
Chris@4 16 [Drupal ESLint](https://www.drupal.org/node/1955232) documentation.
Chris@4 17
Chris@4 18
Chris@4 19 ## Installation
Chris@4 20
Chris@4 21 First, make sure Composer is installed correctly:
Chris@4 22
Chris@4 23 which composer
Chris@4 24
Chris@4 25 If you get composer not found or similar, follow Composer's installation
Chris@4 26 instructions.
Chris@4 27
Chris@5 28 Install Coder (8.x-3.x) in your global Composer directory in your home directory
Chris@4 29 (`~/.composer`):
Chris@4 30
Chris@4 31 composer global require drupal/coder
Chris@4 32
Chris@4 33 To make the `phpcs` and `phpcbf` commands available globally, add the Composer
Chris@4 34 bin path to your `$PATH` variable in `~/.profile`, `~/.bashrc` or `~/.zshrc`:
Chris@4 35
Chris@4 36 export PATH="$PATH:$HOME/.composer/vendor/bin"
Chris@4 37
Chris@4 38 Register the Drupal and DrupalPractice Standard with PHPCS:
Chris@4 39
Chris@4 40 phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
Chris@4 41
Chris@4 42
Chris@4 43 ### Composer Installer Plugins
Chris@4 44
Chris@4 45 The Coder package (>= 8.2.11) now works with Composer Installer Plugins,
Chris@4 46 that find and register standards whenever packages are installed or updated.
Chris@4 47 To use such a plugin within your project, follow these steps.
Chris@4 48
Chris@4 49 composer require --dev dealerdirect/phpcodesniffer-composer-installer
Chris@4 50 composer require --dev drupal/coder
Chris@4 51
Chris@4 52 Now, you will see Drupal and DrupalPractice listed in the available PHP
Chris@4 53 CodeSniffer standards.
Chris@4 54
Chris@4 55 vendor/bin/phpcs -i
Chris@4 56
Chris@4 57 The same can be done for a Composer global installation.
Chris@4 58
Chris@4 59 composer global require dealerdirect/phpcodesniffer-composer-installer
Chris@4 60 composer global require drupal/coder
Chris@4 61
Chris@4 62
Chris@4 63 ## Usage
Chris@4 64
Chris@4 65 Check Drupal coding standards
Chris@4 66
Chris@4 67 phpcs --standard=Drupal /file/to/drupal/example_module
Chris@4 68
Chris@4 69 Check Drupal best practices
Chris@4 70
Chris@4 71 phpcs --standard=DrupalPractice /file/to/drupal/example_module
Chris@4 72
Chris@4 73 Automatically fix coding standards
Chris@4 74
Chris@4 75 phpcbf --standard=Drupal /file/to/drupal/example_module
Chris@4 76
Chris@4 77
Chris@4 78 ## Working with Editors
Chris@4 79
Chris@4 80 Drupal Code Sniffer can be used with various editors.
Chris@4 81
Chris@4 82 Editors:
Chris@4 83
Chris@5 84 - [Atom](https://www.drupal.org/node/1419996)
Chris@4 85 - [Eclipse](https://www.drupal.org/node/1420004)
Chris@4 86 - [Komodo](https://www.drupal.org/node/1419996)
Chris@4 87 - [Netbeans](https://www.drupal.org/node/1420008)
Chris@4 88 - [PhpStorm](https://www.jetbrains.com/help/phpstorm/php-code-sniffer.html)
Chris@4 89 - [Sublime Text](https://www.drupal.org/node/1419996)
Chris@4 90 - [Vim](https://www.drupal.org/node/1419996)
Chris@5 91 - [Visual Studio Code (VSCode)](https://www.drupal.org/node/1419996)
Chris@4 92
Chris@4 93
Chris@4 94 ## Automated Testing (PHPUnit + PHPCS)
Chris@4 95
Chris@4 96 Coder Sniffer comes with a PHPUnit test suite to make sure the sniffs work correctly.
Chris@4 97 Use Composer to install the dependencies:
Chris@4 98
Chris@4 99 composer install
Chris@4 100
Chris@4 101 Then execute the tests:
Chris@4 102
Chris@4 103 ./vendor/bin/phpunit
Chris@4 104
Chris@4 105 Then execute the coding standards checker on Coder itself:
Chris@4 106
Chris@4 107 ./vendor/bin/phpcs
Chris@4 108
Chris@4 109
Chris@4 110 ## Contributing
Chris@4 111
Chris@4 112 1. Make sure an issue exists at https://www.drupal.org/project/issues/coder
Chris@5 113 2. Create a [Pull Request](https://help.github.com/articles/using-pull-requests/) against https://github.com/pfrenssen/coder
Chris@4 114 3. Post a link to the pull request to the issue on drupal.org and set the issue to
Chris@4 115 "needs review"
Chris@4 116
Chris@4 117 Thank you!
Chris@4 118
Chris@4 119
Chris@4 120 ## Maintainers
Chris@5 121
Chris@5 122 - Pieter Frenssen, https://www.drupal.org/u/pfrenssen
Chris@5 123 - Michael Welford, https://www.drupal.org/u/mikejw
Chris@5 124 - Klaus Purer, https://www.drupal.org/u/klausi
Chris@4 125
Chris@4 126
Chris@4 127 ## Credits
Chris@4 128
Chris@4 129 Greg Sherwood and Squiz Pty Ltd, many sniffs are modified copies of their original
Chris@4 130 work on [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer).