1
- HOWTO: Drupal Examples For Developers Coding Standards
2
- =======================================================
1
+ Developing with Coding Standards for Examples for Developers
2
+ ============================================================
3
3
4
4
Examples uses mostly the same coding standards as Drupal core.
5
5
@@ -9,7 +9,7 @@ those used by Examples, please file an issue so that Examples can follow core.
9
9
Examples uses the ` phpcs ` tool to allow for checking PHP coding standards. We
10
10
use the ` drupal/coder ` project for Drupal-specific coding standards.
11
11
12
- We also use ` eslint ` for JavaScript coding standards.
12
+ We also use ` eslint ` for JavaScript coding standards, and ` csslint ` for CSS .
13
13
14
14
Examples has a ` phpcs.xml.dist ` file at the root of the project. phpcs uses this
15
15
file to specify the current coding standards 'sniffs' which code in the project
@@ -30,34 +30,28 @@ Drupal-specific coding standards. We're currently locked to Coder version
30
30
Installing phpcs
31
31
----------------
32
32
33
- Use Composer to add Drupal's Coder project to your root Drupal project. Coder
34
- contains the PHP_CodeSniffer rules we need, and also requires ` phpcs ` .
33
+ Current versions of Drupal 8 core require phpcs and Coder as dev dependencies.
34
+ That means they're already probably installed in your core vendor/ directory .
35
35
36
- Then tell `phpcs' where our Drupal-specific rules are.
36
+ We need to tell ` phpcs ` to use the Drupal coding standard provided by Coder,
37
+ because it isn't configured that way by default.
37
38
38
39
Like this:
39
40
40
41
$ cd my/drupal/root/
41
- $ composer require drupal/coder 8.2.8
42
- // Composer installs Coder, which requires PHP_CodeSniffer as well.
43
- // Configure phpcs to use the Drupal standard rules...
44
- $ ./vendor/bin/phpcs --config-set installed_paths /path/to/drupal/vendor/drupal/coder/coder_sniffer/
42
+ $ ./vendor/bin/phpcs --config-set installed_paths /full/path/to/drupal/vendor/drupal/coder/coder_sniffer/
45
43
// phpcs now knows how to find the Drupal standard. You can test it:
46
44
$ cd core
47
45
$ ../vendor/bin/phpcs -e --standard=Drupal
48
46
// Shows you a bunch of Drupal-related sniffs.
49
47
50
- Note that there is an issue to require Coder and phpcs as part of Drupal core:
51
- https://www.drupal.org/node/2744463 Once this issue is fixed, you shouldn't need
52
- to install phpcs before using it.
53
-
54
48
Running phpcs
55
49
-------------
56
50
57
51
Now you can run phpcs:
58
52
59
53
$ cd modules/examples
60
- $ ../../vendor/bin/phpcs -p -s
54
+ $ ../../vendor/bin/phpcs -ps
61
55
// phpcs uses Exampes' phpcs.xml.dist to verify coding standards.
62
56
// -p shows you progress dots.
63
57
// -s shows you sniff errors in the report.
0 commit comments