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