annotate vendor/drupal/coder/README.md @ 19:fa3358dc1485 tip

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