-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpcs.xml
More file actions
261 lines (210 loc) · 10.5 KB
/
phpcs.xml
File metadata and controls
261 lines (210 loc) · 10.5 KB
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
<?xml version="1.0"?>
<ruleset name="BWL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>A custom set of rules to check styles for a BWL WordPress Themes and plugins.</description>
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="20"/>
<file>.</file>
<!-- Exclude Composer vendor directory. -->
<exclude-pattern>*/.git/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/src/*</exclude-pattern>
<exclude-pattern>*/build/*</exclude-pattern>
<!--
Don't check Plugins, we might not have option (or resources) to fix them.
These paths are specified as relative so that we can include certain files or directories
within these directories using <file>foo/bar</file>.
-->
<exclude-pattern type="relative">*/mu-plugins/*</exclude-pattern>
<exclude-pattern type="relative">*/plugins/*</exclude-pattern>
<!-- Don't check languages -->
<exclude-pattern type="relative">*/languages/*</exclude-pattern>
<!-- db-error.php and object-cache.php, not ours. -->
<exclude-pattern>*/db-error.php</exclude-pattern>
<exclude-pattern>*/object-cache.php</exclude-pattern>
<!-- Tests might have unusual notations which we can't check -->
<exclude-pattern>*/tests/*</exclude-pattern>
<!-- Skip seed data -->
<exclude-pattern>*/data/*</exclude-pattern>
<!-- Skip phinx seeds/migrations -->
<exclude-pattern>db/seeds/</exclude-pattern>
<exclude-pattern>db/migrations/</exclude-pattern>
<!-- Exclude wp core files -->
<exclude-pattern>/wp/wp-admin/*</exclude-pattern>
<exclude-pattern>/wp/wp-includes/*</exclude-pattern>
<exclude-pattern>/wp/wp-*.php</exclude-pattern>
<exclude-pattern>/wp/index.php</exclude-pattern>
<exclude-pattern>/wp/xmlrpc.php</exclude-pattern>
<exclude-pattern>/wp/</exclude-pattern>
<!-- These should act as an reminder that we are not robots. -->
<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="15"/>
</properties>
</rule>
<rule ref="Generic.Metrics.NestingLevel"/>
<!-- We sometimes have used same class name and method name. -->
<rule ref="Generic.NamingConventions.ConstructorName">
<type>warning</type>
</rule>
<!-- Push to move away from deprecated functions, before they are removed. -->
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<!-- There's enough space in the internet for full <?php -->
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<!-- Some functions are forbidden, warn about them. -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="error" value="false"/>
</properties>
</rule>
<!-- These are really awful to debug, so please do not use them. -->
<rule ref="Generic.PHP.NoSilencedErrors">
<properties>
<property name="error" value="false"/>
</properties>
</rule>
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<properties>
<property name="error" value="false"/>
</properties>
</rule>
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<property name="alignMultilineItems" value="!=100"/>
</properties>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<!-- Disallow long array syntax -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<!-- Allow short array syntax -->
<rule ref="Universal.Arrays.DisallowShortArraySyntax.Found">
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace">
<exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
</rule>
<!--
The soft limit on line length MUST be 100 characters
automated style checkers MUST warn but MUST NOT error at the soft limit.
-->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<!-- All PHP files MUST use the Unix LF (linefeed) line ending. -->
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>
<!-- Method arguments with default values MUST go at the end of the argument list. -->
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<!-- This means almost always that developer used an ugly hotfix -->
<rule ref="Squiz.PHP.CommentedOutCode"/>
<!-- Don't allow random white spacing into multiple lines-->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<!-- Don't put unused function parameters into function definition -->
<!-- This might be problematic when using wp actions/filters -->
<!-- This is mostly useful, We should give warning instead -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<!-- No TODO comments, open issues in github instead -->
<rule ref="Generic.Commenting.Todo"/>
<!-- Don't allow oneliner ifs without brackets {} -->
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<!-- No spaces before comma in function calls -->
<!-- This might be problematic when using wp actions/filters -->
<rule ref="Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma"/>
<!--
Ending tags '?>' can be really painful to debug.
Just disallow them in the end of the file
-->
<rule ref="PSR2.Files.ClosingTag.NotAllowed"/>
<!-- <?php tags and constants (true,false,null) need to be lowercase -->
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<!-- Include WordPress Coding Standards with few exclusions -->
<rule ref="WordPress">
<!--
We may want a middle ground though. The best way to do this is to add the
entire ruleset, then rule by rule, remove ones that don't suit a project. We
can do this by running `phpcs` with the '-s' flag, to see the names of the
different Sniffs, as their rules are broken. From here, we can opt to
exclude problematic sniffs like so.
-->
<!--
These are nice but don't have any idea of context
For example we have globals which are not user defined
-->
<exclude name="WordPress.VIP.ValidatedSanitizedInput.MissingUnslash"/>
<exclude name="WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized"/>
<!-- We don't use underscores in valid hook names -->
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores"/>
<!-- Disabled the function restrictions of WP VIP because we need them. -->
<exclude name="WordPress.PHP.RestrictedPHPFunctions"/>
<!-- Use spaces instead of tabs -->
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
<!-- When writing file comments, e.g. template comments, don't require a package tag -->
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag"/>
<!--
This forces you to put '.' in oneline comments.
Maybe full sentences are better than comments with 1-2 words
But we don't want to make people stop using even small comments.
-->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
<!-- Welcome to the dark side -->
<exclude name="WordPress.PHP.YodaConditions"/>
<exclude name="WordPress.PHP.YodaConditions.NotYoda"/>
<!-- Does not comply with DustPress class naming conventions. -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
<!-- There are numerous cases where we want to override WP globals -->
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited"/>
<!-- Exclude the rule that overrides the previously declared rule -->
<exclude name="Squiz.ControlStructures.ControlSignature"/>
<!-- We sometimes comment the elseif block, or similar. -->
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
<!-- ?:-P -->
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
<exclude name="WordPress.DateTime.RestrictedFunctions.date_date" />
<!-- These really shouldn't be excluded, but we have really good caching. -->
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_meta_key" />
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_meta_query" />
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_tax_query" />
<!-- We use these all the time. -->
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound" />
</rule>
<rule ref="WordPress-Extra">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
</rule>
<rule ref="WordPress-Docs">
<exclude name="Squiz.Commenting.FileComment"/>
<exclude name="Squiz.Commenting.FileComment.Missing"/>
</rule>
<!-- Allow dynamic indentation amounts when row starts with an object assignation arrow -->
<rule ref="Universal.WhiteSpace.PrecisionAlignment">
<properties>
<property name="ignoreAlignmentBefore" type="array">
<element value="T_OBJECT_OPERATOR" />
</property>
</properties>
</rule>
<!-- We use these all the time. -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="1"/>
<property name="requiredSpacesBeforeClose" value="1"/>
<!-- ... and for multi-line function calls, there should only be one parameter per line. -->
<property name="allowMultipleArguments" value="true"/>
</properties>
</rule>
</ruleset>