-
Notifications
You must be signed in to change notification settings - Fork 498
/
.phpcs.xml.dist
262 lines (208 loc) · 9.76 KB
/
.phpcs.xml.dist
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Requests"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Requests rules for PHP_CodeSniffer</description>
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->
<!-- Scan all files. -->
<file>.</file>
<!-- Third party files and build files don't need to comply with these coding standards. -->
<exclude-pattern>*/src/Iri\.php$</exclude-pattern>
<exclude-pattern>*/tests/Iri/IriTest\.php$</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/coverage/</exclude-pattern>
<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps"/>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>
<!--
#############################################################################
CHECK FOR PHP CROSS-VERSION COMPATIBILITY
#############################################################################
-->
<config name="testVersion" value="5.6-"/>
<rule ref="PHPCompatibility"/>
<!--
#############################################################################
CODING STYLE RULES
#############################################################################
-->
<!-- Use the WordPress Coding Standards as a basis, but with tweaks. -->
<rule ref="WordPress-Extra">
<!-- No need for this sniff as PHP linting is included in the CI builds against
multiple PHP versions (which is the better solution). -->
<exclude name="Generic.PHP.Syntax"/>
<!-- ==========================================================================
No "nacin-spacing". I.e. don't enforce whitespace on the inside of braces and such.
========================================================================== -->
<!-- Replace by the Squiz version of the sniff which is space-poor in contrast
to the space-rich WPCS sniff. -->
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
<!-- Replaced by the Squiz version of the sniff which doesn't enforce whitespace
around the boolean not `!` operator and enforcement via the Generic sniff. -->
<exclude name="WordPress.WhiteSpace.OperatorSpacing"/>
<!-- Replaced by the Squiz version of the sniff which doesn't enforce whitespace around array index keys. -->
<exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions"/>
<!-- Let spacing before a cast be determined by the operator/parentheses whitespace rule
of the preceding character. -->
<exclude name="WordPress.WhiteSpace.CastStructureSpacing"/>
<!-- ==========================================================================
Forbid "assignments in conditions" instead of enforcing Yoda conditions.
========================================================================== -->
<exclude name="WordPress.PHP.YodaConditions"/>
<!-- A while loop is the only valid control structure where an assignment can be justified. -->
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
<!-- ==========================================================================
Miscellaneous other exclusions.
========================================================================== -->
<!-- This repo complies with PSR 4 for filename conventions. -->
<exclude name="WordPress.Files.FileName"/>
<!-- WPCS demands long arrays. We'll be using short arrays from now on. -->
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
<!-- Ignore WP specific sniffs as Requests is also used outside of a WP context. -->
<exclude name="WordPress.WP"/>
<exclude name="WordPress.DateTime"/>
<exclude name="WordPress.Security"/>
<exclude name="WordPress.PHP.DiscouragedPHPFunctions"/>
</rule>
<!-- ==========================================================================
Enforcement of space-poor code style.
========================================================================== -->
<!-- Overrule the properties set in the WP Core ruleset for several sniffs. -->
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="requiredSpacesAfterOpen" value="0"/>
<property name="requiredSpacesBeforeClose" value="0"/>
</properties>
<!-- Undo the WPCS severity change (exclusion) for spacing before close -->
<severity>5</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="0"/>
<property name="requiredSpacesBeforeClose" value="0"/>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing">
<properties>
<property name="spacing" value="0"/>
</properties>
</rule>
<rule ref="NormalizedArrays.Arrays.ArrayBraceSpacing">
<properties>
<property name="spacesSingleLine" value="0"/>
</properties>
</rule>
<!-- Include replacement sniffs which enforce the opposite of WPCS for several excluded sniffs. -->
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing">
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.LineAfterClose"/>
</rule>
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<!-- Enforce no space after the boolean not `!` operator. -->
<rule ref="Generic.Formatting.SpaceAfterNot">
<properties>
<property name="spacing" value="0"/>
</properties>
</rule>
<!-- ==========================================================================
Disallow Yoda conditions.
========================================================================== -->
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
<!-- ==========================================================================
Enforce short arrays.
========================================================================== -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->
<!-- Allow error silencing only for a select group of functions. -->
<rule ref="WordPress.PHP.NoSilencedErrors">
<properties>
<property name="customAllowedFunctionsList" type="array">
<element value="gzdecode"/>
<element value="gzinflate"/>
<element value="gzuncompress"/>
</property>
</properties>
</rule>
<!-- Make sure everything in the global namespace is prefixed. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="Requests"/>
<element value="WpOrg\Requests"/>
</property>
</properties>
<exclude-pattern>*/examples/*\.php$</exclude-pattern>
<exclude-pattern>*/tests/bootstrap\.php$</exclude-pattern>
</rule>
<!-- Simplify alignment rules for multiline arrays. -->
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<!-- No need to adjust alignment of large arrays when the item with the largest key is removed. -->
<property name="exact" value="false"/>
<!-- Don't align multi-line items if ALL items in the array are multi-line. -->
<property name="alignMultilineItems" value="!=100"/>
<!-- The array assignment operator should always be on the same line as the array key. -->
<property name="ignoreNewlines" value="false"/>
</properties>
</rule>
<!-- In contrast to WPCS (40%), we allow a slightly higher percentage. -->
<rule ref="Squiz.PHP.CommentedOutCode">
<properties>
<property name="maxPercentage" value="50"/>
</properties>
</rule>
<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs.
#############################################################################
-->
<!-- ==========================================================================
Example code
========================================================================== -->
<!-- Using var_dump() in example code is fine. -->
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_var_dump">
<exclude-pattern>/examples/[^/]+\.php$</exclude-pattern>
</rule>
<!-- ==========================================================================
Test code
========================================================================== -->
<!-- Overloaded methods to make the expected exceptions more specific. -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod">
<exclude-pattern>/tests/Transport/*\.php$</exclude-pattern>
</rule>
<!-- Allow single-line multi-item associative arrays in the unit tests. -->
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<!-- Method declarations in test classes can use camelCase for compatibility with PHPUnit and consistency. -->
<rule ref="WordPress.NamingConventions.ValidFunctionName">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<!-- Using var_export() in test code is fine. -->
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_var_export">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
<!-- Using set_error_handler() in test code is fine. -->
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
</ruleset>