@@ -91,20 +91,45 @@ internationalization functions are called with the proper text domain.
91
91
92
92
## PSR-1 & PSR-2
93
93
94
- See http://www.php-fig.org/psr/psr-1/ and http://www.php-fig.org/psr/psr-2/
94
+ See http://www.php-fig.org/psr/psr-1/ and http://www.php-fig.org/psr/psr-2/ .
95
+
96
+ The tree of used rules are listed in the ` /docs/rules-list/psr.md ` file in this repo.
95
97
96
98
97
99
## VariableAnalysis
98
100
99
101
See https://github.com/sirbrillig/phpcs-variable-analysis
100
102
103
+ The tree of used rules are listed in the ` /docs/rules-list/variable-analysis.md ` file in this repo.
104
+
101
105
102
106
## Neutron Standard
103
107
104
108
See https://github.com/Automattic/phpcs-neutron-standard
105
109
106
- All Neutron Standard rules are included except "Function size" (handles in custom rules, see below)
107
- and "Variable Functions" rules.
110
+ Almost all Neutron Standard rules are included.
111
+
112
+ The tree of used rules are listed in the ` /docs/rules-list/neutron-standard.md ` file in this repo.
113
+
114
+
115
+ ## WordPress Coding Standard
116
+
117
+ To ensure code quality, and compatibility with VIP, several WordPress Coding Standard rules have been
118
+ "cherry picked" from WP coding standards.
119
+
120
+ See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards .
121
+
122
+ The tree of used rules are listed in the ` /docs/rules-list/wordpress.md ` file in this repo.
123
+
124
+
125
+ ## Generic Rules
126
+
127
+ Some rules are also included from PHP cCode Sniffer itself. Those rules fall in the
128
+ "Generic", "Squiz" and "PEAR" namespace.
129
+
130
+ Those rules are included by other styles, mainly by PSR-1 and PSR-2.
131
+
132
+ The tree of used rules are listed in the ` /docs/rules-list/generic.md ` file in this repo.
108
133
109
134
110
135
## Custom Rules
@@ -122,47 +147,121 @@ Customs rules are:
122
147
- Max 10 properties per class
123
148
- Max 50 lines per method
124
149
150
+ The tree of used rules are listed in the ` /docs/rules-list/custom.md ` file in this repo.
125
151
126
- ## WordPress Coding Standard
152
+ -------------
127
153
128
- To ensure code quality, and compatibility with VIP, several WordPress Coding Standard rules have been
129
- "cherry picked" from WP coding standards.
130
- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards .
154
+ # Removing or Disabling Rules
155
+
156
+ ## Rules Tree
157
+
158
+ Sometimes it is necessary to don't follow some rules.
159
+ To avoid error reporting is is possible to:
160
+
161
+ - Removing rules for an entire project via configuration
162
+ - Disabling rules from code, only is specific places
163
+
164
+ In both cases it is possible to remove or disable:
165
+
166
+ - a whole standard
167
+ - a standard subset
168
+ - a single sniff
169
+ - a single rules
131
170
132
- Included rules are:
133
-
134
- - ` WordPress.VIP.SessionVariableUsage ` - Avoid usages of ` $_SESSION ` super global
135
- - ` VIP.SessionFunctionsUsage ` - Avoid usages of session-related functions
136
- - ` WordPress.VIP.SuperGlobalInputUsage ` - Avoid usages of sulerglobals: ` $_GET ` , ` $_POST ` , etc
137
- - ` WordPress.VIP.ValidatedSanitizedInput ` - Avoid non-validated/sanitized input (` $_GET ` , ` $_POST ` , etc)
138
- - ` WordPress.Security.EscapeOutput ` - Verifies that all outputted strings are escaped.
139
- - ` WordPress.Security.NonceVerification ` - Checks that nonce verification accompanies form processing.
140
- - ` WordPress.WP.AlternativeFunctions.curl ` - Discourages the use of cURL functions and suggests WP alternatives.
141
- - ` WordPress.WP.DiscouragedConstants ` - Warns against usage of discouraged WP constants
142
- - ` WordPress.WP.I18n ` - Makes sure WP internationalization functions are used properly. Also checks text domain if set in ` phpcs.xml `
143
- - ` WordPress.Arrays.CommaAfterArrayItem ` - Ensure last item of arrays have a comma
144
- - ` WordPress.PHP.StrictComparisons ` - Enforces Strict Comparison checks
145
- - ` WordPress.PHP.StrictInArray ` - Prevent calling ` in_array() ` , ` array_search() ` and ` array_keys() ` without ` true ` as the 3rd parameter
146
- - ` WordPress.PHP.POSIXFunctions ` - Suggest usage of PCRE functions (` preg_* ` ) instead of POSIX alternative
147
- - ` WordPress.PHP.RestrictedPHPFunctions ` - Prevent usage of ` create_function `
148
- - ` WordPress.PHP.DiscouragedPHPFunctions ` - Discourage usage of soem PHP functions (runtime configuration, system calls)
149
- - ` WordPress.PHP.DevelopmentFunctions ` - Prevent usage of development PHP functions (` error_log ` , ` var_dump ` , ` var_export ` , ` print_r ` ...)
150
-
151
- Any of these rules (just like the others) can be excluded in the ` phpcs.xml ` , using a syntax like this:
171
+ The for things above are in hierarchical relationship: a _ standard_ is made of one
172
+ or more _ subset_ , each subset contains one or more _ sniff_ and each sniff contains
173
+ one or more rule.
174
+
175
+ The folder ` /docs/rules-list/ ` of this repo contains 6 files, each of them contain
176
+ the rules _ tree_ for one (or few related) standard(s).
177
+
178
+ For example, in the file ` docs/rules-list/psr.md ` is is possible to read something
179
+ like:
180
+
181
+ ```
182
+ - PSR1
183
+ - PSR1.Classes
184
+ - PSR1.Classes.ClassDeclaration
185
+ - PSR1.Classes.ClassDeclaration.MultipleClasses
186
+ ```
187
+
188
+ Where:
189
+ - "_ PSR1_ " is the standard
190
+ - "_ PSR1.Classes_ " is the subset
191
+ - "_ PSR1.Classes.ClassDeclaration_ " is the sniff
192
+ - "_ PSR1.Classes.ClassDeclaration.MultipleClasses_ " is the rule
193
+
194
+
195
+ ## Remove rules via configuration file
196
+
197
+ Rules can be removed for the entire project by using a custom ` phpcs.xml ` , with
198
+ a syntax like this:
152
199
153
200
``` xml
154
201
<?xml version =" 1.0" ?>
155
202
<ruleset name =" MyProjectCodingStandard" >
156
203
157
204
<rule ref =" Inpsyde" >
158
- <exclude name =" WordPress.PHP.DevelopmentFunctions " />
205
+ <exclude name =" PSR1.Classes.ClassDeclaration " />
159
206
</rule >
160
207
161
208
</ruleset >
162
209
```
163
210
211
+ In the example above, the _ sniff_ ` PSR1.Classes.ClassDeclaration ` (and all the rules
212
+ it contains) has been removed.
213
+
214
+ Replacing ` PSR1.Classes.ClassDeclaration ` with just ` PSR1 ` had been possible to
215
+ remove the whole standard, while replacing it with ` PSR1.Classes.ClassDeclaration.MultipleClasses `
216
+ only the single rule is removed.
217
+
218
+ ## Remove rules via code comments
219
+
220
+ If it is necessary to remove a rule/sniff/standard subset/standard only in
221
+ specific place in the code, it is possible to use special comments that starts
222
+ with:
223
+
224
+ ``` php
225
+ // phpcs:disable
226
+ ```
227
+
228
+ followed by the what you want to to remove.
229
+
230
+ For example: ` // phpcs:disable PSR1.Classes.ClassDeclaration ` .
231
+
232
+ From the point the comment is encountered to the end of the file, the requested
233
+ rule/sniff/standard subset/standard is not checked anymore.
234
+
235
+ To re-enable it is necessary to use a similar syntax, but this time using
236
+ ` phpcs:enable ` instead of ` phpcs:disable ` .
237
+
238
+ It worth nothing:
239
+
240
+ - ` phpcs:disable ` and ` phpcs:enable ` can be used without anything else, in this
241
+ case the check for * all* rules are disabled/enabled.
242
+ - Disabling / enabling comments could be embedded in doc block comments at
243
+ file/class/method level. For example:
244
+
245
+ ``` php
246
+ class Foo
247
+ {
248
+ /**
249
+ * @param mixed $a
250
+ * @param mixed $b
251
+ *
252
+ * phpcs:disable NeutronStandard.Functions.TypeHint.NoArgumentType
253
+ */
254
+ public function test($a, $b)
255
+ {
256
+ // phpcs:enable
257
+ }
258
+ }
259
+ ```
260
+
261
+
164
262
-------------
165
263
264
+
166
265
# IDE integration
167
266
168
267
## PhpStorm
0 commit comments