forked from Yoast/wordpress-seo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.phpcs.xml.dist
328 lines (273 loc) · 12.3 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
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
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Yoast SEO Free"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Yoast SEO Free rules for PHP_CodeSniffer</description>
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->
<file>.</file>
<!-- Exclude dependency related files and generated files from being scanned. -->
<exclude-pattern type="relative">^artifact/*\.php$</exclude-pattern>
<exclude-pattern type="relative">^config/php-scoper/*\.php$</exclude-pattern>
<exclude-pattern type="relative">^src/generated/*\.php$</exclude-pattern>
<exclude-pattern type="relative">^languages/*\.php$</exclude-pattern>
<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
<!-- Show progress, show the error codes for each message (source). -->
<arg value="sp"/>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="."/>
<!-- Check up to 12 files simultaneously. -->
<arg name="parallel" value="12"/>
<!-- Cache the results between runs. -->
<arg name="cache" value="./.cache/phpcs-free.cache"/>
<!--
#############################################################################
USE THE YoastCS RULESET
#############################################################################
-->
<rule ref="Yoast">
<properties>
<!-- Provide the plugin specific prefixes for all naming related sniffs. -->
<property name="prefixes" type="array">
<element value="Yoast\WP\SEO"/>
<element value="yoast_seo"/>
</property>
<!-- Set the custom test class list for all sniffs which use it in one go.
Ref: https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-unit-test-classes
-->
<property name="custom_test_classes" type="array">
<element value="Yoast\WP\SEO\Tests\Unit\TestCase"/>
<element value="Yoast\WP\SEO\Tests\WP\TestCase"/>
</property>
<property name="psr4_paths" type="array">
<element key="Yoast\WP\SEO\Tests\\" value="tests/"/>
</property>
</properties>
</rule>
<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration">
<!-- YoastCS only applies this rule to test files. Overrule it to also apply to src files. -->
<include-pattern>*/config/*\.php$</include-pattern>
<include-pattern>*/src/*\.php$</include-pattern>
<exclude-pattern>*/src/deprecated/*\.php$</exclude-pattern>
<exclude-pattern>*/src/config/migrations/*\.php$</exclude-pattern>
</rule>
<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="wordpress-seo"/>
<element value="default"/>
</property>
</properties>
</rule>
<rule ref="Yoast.Files.FileName">
<properties>
<property name="excluded_files_strict_check" type="array">
<!-- Don't trigger on the main file(s) as renaming it would deactivate the plugin. -->
<element value="wp-seo.php"/>
<element value="wp-seo-main.php"/>
<!-- Don't trigger on select view related files. -->
<element value="admin/views/tool-bulk-editor.php"/>
</property>
<!-- Remove the following prefixes from the names of object structures. -->
<property name="oo_prefixes" type="array">
<element value="yoast_seo"/>
<!-- Temporary: once all prefixes have been fixed, these two elements should be removed. -->
<element value="wpseo"/>
<element value="yoast"/>
</property>
</properties>
<!-- Exclude the migrations directory from filename checks, as we do not have control over this format -->
<exclude-pattern>/src/config/migrations/*\.php$</exclude-pattern>
</rule>
<rule ref="Yoast.NamingConventions.ObjectNameDepth">
<properties>
<property name="max_words" value="5" />
<property name="recommended_max_words" value="5" />
</properties>
</rule>
<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<!-- Indicate which directories should be treated as project root directories for
path-to-namespace translations. -->
<property name="src_directory" type="array">
<element value="config"/>
<element value="src"/>
<element value="src/deprecated/src"/>
</property>
</properties>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions">
<properties>
<!-- We discovered that WP_Filesystem can lead to unexpected behaviour.
See https://github.com/Yoast/wordpress-seo/pull/15713 -->
<property name="exclude" type="array" extend="true">
<element value="file_system_operations"/>
</property>
</properties>
</rule>
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<property name="maxColumn" value="70"/>
</properties>
</rule>
<!-- Make sure custom capabilities are recognized. -->
<rule ref="WordPress.WP.Capabilities">
<properties>
<property name="custom_capabilities" type="array">
<element value="wpseo_manage_network_options"/>
<element value="wpseo_manage_options"/>
</property>
</properties>
</rule>
<!-- Excluded in WPCS, but the exclusion does not work well with a code base using short arrays.
This may lead to some duplicate notices, but rather that, than these issues not being flagged.
Note: this change will be included in YoastCS 3.1.1 and this tweak can be removed after that.
-->
<rule ref="Universal.WhiteSpace.CommaSpacing.SpaceBeforeInFunctionCall">
<severity>5</severity>
</rule>
<rule ref="Universal.WhiteSpace.CommaSpacing.TooMuchSpaceAfterInFunctionCall">
<severity>5</severity>
</rule>
<rule ref="Universal.WhiteSpace.CommaSpacing.NoSpaceAfterInFunctionCall">
<severity>5</severity>
</rule>
<!--
##########################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs.
#############################################################################
-->
<!-- For named parameter support, the parameters in the overloaded methods *must*
mirror the parameter name as used in Symfony itself.
These cannot be changed until Symfony itself changes the names. -->
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound">
<exclude-pattern>/config/dependency-injection/custom-loader\.php$</exclude-pattern>
</rule>
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.resourceFound">
<exclude-pattern>/config/dependency-injection/custom-loader\.php$</exclude-pattern>
</rule>
<!-- Exclude the "lib" folder from select naming conventions.
The intention is to extract this to a separate package, so the names are
based on the "future" package. -->
<rule ref="Yoast.NamingConventions.NamespaceName">
<exclude-pattern type="relative">/lib/([a-z-]+/)?[^/]+\.php$</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound">
<exclude-pattern type="relative">/lib/([a-z-]+/)?[^/]+\.php$</exclude-pattern>
</rule>
<!-- Exclude select directories from the object depth naming convention check. -->
<rule ref="Yoast.NamingConventions.ObjectNameDepth.MaxExceeded">
<exclude-pattern>/src/config/migrations/*</exclude-pattern>
</rule>
<!-- Exclude third-party from being checked too roughly. -->
<rule ref="Yoast.NamingConventions.NamespaceName.TooLong">
<exclude-pattern>/src/generators/schema/third-party/*</exclude-pattern>
</rule>
<!-- DEPRECATED CODE -->
<!-- Files which are excluded for code-coverage in the phpunit.xml.dist file should
also be excluded for this sniff.
Note: the lists in phpunit.xml.dist and here should be kept in sync! -->
<rule ref="Yoast.Commenting.CodeCoverageIgnoreDeprecated">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
<exclude-pattern>/inc/wpseo-functions-deprecated\.php$</exclude-pattern>
</rule>
<!-- Ignore unused function parameters in deprecated functionality. -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
<exclude-pattern>/inc/wpseo-functions-deprecated\.php$</exclude-pattern>
</rule>
<!-- Ignore unused variables in deprecated functionality. -->
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
<exclude-pattern>/inc/wpseo-functions-deprecated\.php$</exclude-pattern>
</rule>
<!-- Exclude deprecated code from select sniffs regarding naming conventions.
These classes are still available to prevent BC-breaks and renaming them would
create a BC-break. -->
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
</rule>
<rule ref="Yoast.Files.FileName">
<exclude-pattern>/src/deprecated/*</exclude-pattern>
</rule>
<!-- TEST CODE -->
<!-- Valid usage: For testing purposes, some non-prefixed globals are being created, which is fine. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>/tests/*/bootstrap\.php$</exclude-pattern>
</rule>
<!-- Direct DB queries to retrieve the comparison data for tests or to create a test case, is fine. -->
<rule ref="WordPress.DB.DirectDatabaseQuery">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
<!-- Valid usage: For setting up/tearing down a test situation, it is better to use the PHP native functions. -->
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>/tests/WP/Formatter/Metabox_Formatter_Test\.php$</exclude-pattern>
</rule>
<!-- Valid usage: Mocking the WP native wp_parse_url() function. -->
<rule ref="WordPress.WP.AlternativeFunctions.parse_url_parse_url">
<exclude-pattern>/tests/Unit/*\.php$</exclude-pattern>
</rule>
<!-- Test code does not go into production, so security is not an issue. -->
<rule ref="WordPress.Security">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
<!-- Changing the cron interval to test things, is fine. -->
<rule ref="WordPress.WP.CronInterval">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
<!-- For documentation of the double/mock classes, please refer to the _real_ classes. -->
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>/tests/*/Doubles/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>/tests/*/Doubles/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.VariableComment.Missing">
<exclude-pattern>/tests/*/Doubles/*</exclude-pattern>
</rule>
<!--
#############################################################################
TEMPORARY ADJUSTMENTS
Adjustments which should be removed once the associated issue has been resolved.
#############################################################################
-->
<!-- Temporary: Only enable the file name rules for the "new" code for now.
The "old" code has a lot of violations against this rule.
Fixing this should be a coordinated effort, which is why we will ignore
this rule for the "old" code for now.
-->
<rule ref="Yoast.Files.FileName">
<include-pattern>/config/*\.php$</include-pattern>
<include-pattern>/lib/*\.php$</include-pattern>
<include-pattern>/src/*\.php$</include-pattern>
<include-pattern>/tests/*\.php$</include-pattern>
</rule>
<!-- Only enable the prefix all globals rules for the "new" code for now.
The "old" code has a lot of violations against this rule, mostly inconsistent
prefixes. Fixing this should be a coordinated effort, which is why we will ignore
this rule for the "old" code for now.
-->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<include-pattern>*/config/*\.php$</include-pattern>
<include-pattern>*/lib/*\.php$</include-pattern>
<include-pattern>*/src/*\.php$</include-pattern>
<include-pattern>*/tests/*\.php$</include-pattern>
<!-- Exclude hooks everywhere for the time being until the prefixes will be fixed. -->
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound"/>
</rule>
</ruleset>