summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 7ce07bbf05a54b9655850947018bfe5c8c2d044f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Coder

[![Build Status](https://travis-ci.org/pfrenssen/coder.svg?branch=8.x-2.x)](https://travis-ci.org/pfrenssen/coder)

Coder is a library for automated Drupal code reviews and coding standard fixes. It
defines rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)

Built-in support for:
- "Drupal": Coding Standards https://www.drupal.org/coding-standards
- "DrupalPractice": Best practices for Drupal module development

Online documentation: https://www.drupal.org/node/1419980

Note that Javascript support has been removed. To check and fix Javascript files
please use [ESLint](http://eslint.org/) and see the
[Drupal ESLint](https://www.drupal.org/node/1955232) documentation.


## Installation

First, make sure Composer is installed correctly:
```
which composer
```

If you get composer not found or similar, follow Composer's installation
instructions.

Install Coder (8.x-2.x) in your global Composer directory in your home directory
(~/.composer):
```
composer global require drupal/coder
```

To make the phpcs and phpcbf commands available globally, add the composer bin path
to your $PATH variable in ~/.profile, ~/.bashrc or ~/.zshrc:
```
export PATH="$PATH:$HOME/.composer/vendor/bin"
```

Register the Drupal and DrupalPractice Standard with PHPCS:
```
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
```


## Usage

Check Drupal coding standards
```
phpcs --standard=Drupal /file/to/drupal/example_module
```

Check Drupal best practices
```
phpcs --standard=DrupalPractice /file/to/drupal/example_module
```

Automatically fix coding standards
```
phpcbf --standard=Drupal /file/to/drupal/example_module
```


## Working with Editors

Drupal Code Sniffer can be used with various editors.

Editors:

* Eclipse: https://www.drupal.org/node/1420004
* Komodo: https://www.drupal.org/node/1419996
* Netbeans: https://www.drupal.org/node/1420008
* Sublime Text: https://www.drupal.org/node/1419996
* vim: https://www.drupal.org/node/1419996


## Automated Testing (PHPUnit + PHPCS)

Coder Sniffer comes with a PHPUnit test suite to make sure the sniffs work correctly.
Use Composer to install the dependencies:

```
composer install
```

Then execute the tests:
```
./vendor/bin/phpunit
```

Then execute the coding standards checker on Coder itself:
```
./vendor/bin/phpcs
```


## Contributing

1. Make sure an issue exists at https://www.drupal.org/project/issues/coder
2. Create a [pull request](https://help.github.com/articles/using-pull-requests/) against https://github.com/pfrenssen/coder
3. Post a link to the pull request to the issue on drupal.org and set the issue to
   "needs review"

Thank you!


## Maintainers
Pieter Frenssen, https://www.drupal.org/u/pfrenssen


## Credits

Greg Sherwood and Squiz Pty Ltd, many sniffs are modified copies of their original
work on [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer).