-
Notifications
You must be signed in to change notification settings - Fork 8
/
phpcs.xml
423 lines (355 loc) · 18.8 KB
/
phpcs.xml
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Gutenberg Plugin">
<description>Coding standard for Search Regex plugin. Based on WordPress coding standards, but without the annoying Yoda and alignment options</description>
<config name="testVersion" value="7.0-"/>
<file>includes/</file>
<file>search-regex.php</file>
<exclude-pattern>bin/</exclude-pattern>
<exclude-pattern>images/</exclude-pattern>
<exclude-pattern>languages/</exclude-pattern>
<exclude-pattern>src/</exclude-pattern>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
<exclude-pattern>node_modules/</exclude-pattern>
<exclude-pattern>build/</exclude-pattern>
<exclude-pattern>.vscode/</exclude-pattern>
<exclude-pattern>.github/</exclude-pattern>
<rule ref="WordPress-Core">
<!-- these I dont like -->
<exclude name="WordPress.PHP.YodaConditions.NotYoda"/>
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned"/>
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/>
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<!-- documentation warnings -->
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
<exclude name="Squiz.Commenting.FileComment.Missing"/>
<exclude name="Squiz.Commenting.ClassComment.Missing"/>
<exclude name="Squiz.Commenting.VariableComment.Missing"/>
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
<exclude name="Squiz.Commenting.FileComment.WrongStyle"/>
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable"/>
<exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments"/>
</rule>
<rule ref="Generic.Arrays">
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<exclude name="Generic.Arrays.DisallowLongArraySyntax.Found"/>
</rule>
<rule ref="Universal.Arrays">
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
</rule>
<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra"/>
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="search-regex,default"/>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis"/>
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>
<rule ref="WordPress.WP.I18n.MissingArgDomainDefault" />
<arg value="ps"/>
<arg name="extensions" value="php"/>
<arg name="colors"/>
<arg name="tab-width" value="4"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Classes.DuplicateClassName"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<properties>
<property name="allowMultiline" value="true"/>
</properties>
</rule>
<rule ref="Squiz.PHP.NonExecutableCode"/>
<rule ref="Squiz.Operators.IncrementDecrementUsage"/>
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
<rule ref="Squiz.Functions.FunctionDuplicateArgument"/>
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/>
<rule ref="PEAR.Files.IncludingFile"/>
<rule ref="PEAR.Files.IncludingFile.UseInclude">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.BracketsNotRequired">
<type>warning</type>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequire">
<type>warning</type>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
<type>warning</type>
</rule>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<type>warning</type>
</rule>
<rule ref="WordPress.Security.EscapeOutput"/>
<!-- Encourage use of wp_safe_redirect() to avoid open redirect vulnerabilities.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1264 -->
<rule ref="WordPress.Security.SafeRedirect"/>
<!-- Verify that a nonce check is done before using values in superglobals.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/73 -->
<rule ref="WordPress.Security.NonceVerification"/>
<rule ref="WordPress.PHP.DevelopmentFunctions"/>
<rule ref="WordPress.PHP.DiscouragedPHPFunctions"/>
<rule ref="WordPress.WP.DeprecatedFunctions"/>
<rule ref="WordPress.WP.DeprecatedClasses"/>
<rule ref="WordPress.WP.DeprecatedParameters"/>
<rule ref="WordPress.WP.DeprecatedParameterValues"/>
<rule ref="WordPress.WP.AlternativeFunctions"/>
<rule ref="WordPress.WP.DiscouragedConstants"/>
<rule ref="WordPress.WP.DiscouragedFunctions"/>
<rule ref="WordPress.WP.EnqueuedResources"/>
<!-- Warn against overriding WP global variables.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/26 -->
<rule ref="WordPress.WP.GlobalVariablesOverride"/>
<!-- Check that in_array() and array_search() use strict comparisons.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/399
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/503 -->
<rule ref="WordPress.PHP.StrictInArray"/>
<!-- Make the translators comment check which is included in core stricter. -->
<rule ref="WordPress.WP.I18n.MissingTranslatorsComment">
<type>error</type>
</rule>
<rule ref="WordPress.WP.I18n.TranslatorsCommentWrongStyle">
<type>error</type>
</rule>
<!-- Verify that everything in the global namespace is prefixed. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals"/>
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1157 -->
<rule ref="WordPress.Security.PluginMenuSlug"/>
<rule ref="WordPress.WP.CronInterval"/>
<rule ref="WordPress.WP.PostsPerPage"/>
<rule ref="WordPress.PHP.PregQuoteDelimiter"/>
<!-- Commented out code should not be committed.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1463 -->
<rule ref="Squiz.PHP.CommentedOutCode">
<properties>
<property name="maxPercentage" value="40"/>
</properties>
</rule>
<!-- Check for single blank line after namespace declaration. -->
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
<!-- Check enqueue and register styles and scripts to have version and in_footer parameters explicitly set.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1146 -->
<rule ref="WordPress.WP.EnqueuedResourceParameters"/>
<!-- Discourage use of the backtick operator (execution of shell commands).
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/646 -->
<rule ref="Generic.PHP.BacktickOperator"/>
<!-- Check for PHP Parse errors.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/522 -->
<rule ref="Generic.PHP.Syntax"/>
<!-- Covers rule: Use single and double quotes when appropriate.
If you're not evaluating anything in the string, use single quotes. -->
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="exact" value="false"/>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
<property name="ignoreIndentationTokens" type="array" value="T_HEREDOC,T_NOWDOC,T_INLINE_HTML"/>
</properties>
</rule>
<rule ref="WordPress.Arrays.ArrayIndentation"/>
<!-- Covers rule: Use real tabs and not spaces. -->
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<!-- Generic array layout check. -->
<!-- Covers rule: For associative arrays, values should start on a new line.
Also covers various single-line array whitespace issues. -->
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing"/>
<!-- Covers rule: For switch structures case should indent one tab from the
switch statement and break one tab from the case statement. -->
<rule ref="PSR2.ControlStructures.SwitchDeclaration">
<!-- Prevent duplicate messages for the same issue. Covered by other sniffs. -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.NotLower"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLine"/>
</rule>
<!-- Covers rule: ... while spaces can be used mid-line for alignment. -->
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<!-- Covers rule: Braces should always be used, even when they are not required. -->
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
<!--
#############################################################################
Handbook: PHP - Regular Expressions.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#regular-expressions
#############################################################################
-->
<!-- Covers rule: Perl compatible regular expressions should be used in preference
to their POSIX counterparts. -->
<rule ref="WordPress.PHP.POSIXFunctions"/>
<!-- Rule: Never use the /e switch, use preg_replace_callback instead.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/632 -->
<!-- Rule: It's most convenient to use single-quoted strings for regular expressions.
Already covered by Squiz.Strings.DoubleQuoteUsage -->
<!--
#############################################################################
Handbook: PHP - Opening and Closing PHP Tags.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#opening-and-closing-php-tags
#############################################################################
-->
<!-- Covers rule: When embedding multi-line PHP snippets within a HTML block, the
PHP open and close tags must be on a line by themselves. -->
<rule ref="Squiz.PHP.EmbeddedPhp">
<exclude name="Squiz.PHP.EmbeddedPhp.SpacingBefore"/>
<exclude name="Squiz.PHP.EmbeddedPhp.Indent"/>
<exclude name="Squiz.PHP.EmbeddedPhp.OpenTagIndent"/>
<exclude name="Squiz.PHP.EmbeddedPhp.SpacingAfter"/>
</rule>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.DisallowAlternativePHPTags"/>
<!--
#############################################################################
Handbook: PHP - Remove Trailing Spaces.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#remove-trailing-spaces
#############################################################################
-->
<!-- Covers rule: Remove trailing whitespace at the end of each line of code. -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<!-- Covers rule: Omitting the closing PHP tag at the end of a file is preferred. -->
<rule ref="PSR2.Files.ClosingTag"/>
<!--
#############################################################################
Handbook: PHP - Space Usage.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#space-usage
#############################################################################
-->
<!-- Covers rule: Always put spaces after commas, and on both sides of logical,
comparison, string and assignment operators. -->
<rule ref="WordPress.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<!-- Covers rule: Put spaces on both sides of the opening and closing parenthesis of
if, elseif, foreach, for, and switch blocks. -->
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing"/>
<!-- Covers rule: Define a function like so: function my_function( $param1 = 'foo', $param2 = 'bar' ) { -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
<properties>
<property name="checkClosures" value="true"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
<property name="requiredSpacesAfterOpen" value="1"/>
<property name="requiredSpacesBeforeClose" value="1"/>
</properties>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose"/>
</rule>
<!-- Covers rule: Call a function, like so: my_function( $param1, func_param( $param2 ) ); -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="1"/>
<property name="requiredSpacesBeforeClose" value="1"/>
</properties>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity phpcs-only="true">0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity phpcs-only="true">0</severity>
</rule>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<!-- Rule: Perform logical comparisons, like so: if ( ! $foo ) { -->
<!-- Covers rule: When type casting, do it like so: $foo = (boolean) $bar; -->
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="WordPress.WhiteSpace.CastStructureSpacing"/>
<!-- Covers rule: ... array items, only include a space around the index if it is a variable. -->
<rule ref="WordPress.Arrays.ArrayKeySpacingRestrictions"/>
<!-- Rule: In a switch block, there must be no space before the colon for a case statement. -->
<!-- Covered by the PSR2.ControlStructures.SwitchDeclaration sniff. -->
<!-- Rule: Similarly, there should be no space before the colon on return type declarations. -->
<!--
#############################################################################
Handbook: PHP - Formatting SQL statements.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#formatting-sql-statements
#############################################################################
-->
<!-- Rule: Always capitalize the SQL parts of the statement like UPDATE or WHERE.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/639 -->
<!-- Rule: Functions that update the database should expect their parameters to lack
SQL slash escaping when passed.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/640 -->
<!-- Rule: in $wpdb->prepare - only %s and %d are used as placeholders. Note that they are not "quoted"! -->
<rule ref="WordPress.DB.PreparedSQLPlaceholders"/>
<!-- Covers rule: Escaping should be done as close to the time of the query as possible,
preferably by using $wpdb->prepare() -->
<rule ref="WordPress.DB.PreparedSQL"/>
<rule ref="WordPress.DB.RestrictedFunctions"/>
<rule ref="WordPress.DB.RestrictedClasses"/>
<!--
#############################################################################
Handbook: PHP - Naming Conventions.
Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions
#############################################################################
-->
<!-- Covers rule: Use lowercase letters in variable, action, and function names.
Separate words via underscores. -->
<rule ref="WordPress.NamingConventions.ValidFunctionName"/>
<rule ref="WordPress.NamingConventions.ValidHookName"/>
<rule ref="WordPress.NamingConventions.ValidVariableName"/>
<!-- Covers rule: Class names should use capitalized words separated by underscores. -->
<rule ref="PEAR.NamingConventions.ValidClassName"/>
<!-- Covers rule: Constants should be in all upper-case with underscores separating words. -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<!-- Rule: In a switch statement... If a case contains a block, then falls through
to the next block, this must be explicitly commented. -->
<!-- Covered by the PSR2.ControlStructures.SwitchDeclaration sniff. -->
<!-- Rule: The eval() construct is very dangerous, and is impossible to secure. ... these must not be used. -->
<rule ref="Squiz.PHP.Eval"/>
<rule ref="Squiz.PHP.Eval.Discouraged">
<type>error</type>
<message>eval() is a security risk so not allowed.</message>
</rule>
<!-- Rule: create_function() function, which internally performs an eval(),
is deprecated in PHP 7.2. Both of these must not be used. -->
<rule ref="WordPress.PHP.RestrictedPHPFunctions"/>
<!-- Ignore snake case error in parser -->
<rule ref="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase">
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
</rule>
<!-- Ignore filename error since it requires WP core build process change -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
</rule>
<rule ref="VariableAnalysis"/>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable">
<type>error</type>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="search-regex"/>
</property>
</properties>
</rule>
</ruleset>