Make WordPress Core

source: tags/6.7.4/phpcs.xml.dist

Last change on this file was 58925, checked in by dmsnell, 15 months ago

HTML API: Parse DOCTYPE tokens and set HTML parser mode accordingly.

This patch adds until-now missing code to parse the structure of HTML DOCTYPE declarations. The DOCTYPE is mostly unused but can dictate the document compatability mode, which governs whether CSS class names match in a ASCII-case-insensitive way or not, and whether TABLE elements close an open P element.

The DOCTYPE information is made available through a new method on the Tag Processor, get_doctype_info().

Developed in https://github.com/wordpress/wordpress-develop/pull/7195
Discussed in https://core.trac.wordpress.org/ticket/61576

Props dmsnell, jonsurrell.
See #61576.

  • Property svn:eol-style set to native
File size: 15.1 KB
Line 
1<?xml version="1.0"?>
2<ruleset name="WordPress Coding Standards">
3        <description>Apply WordPress Coding Standards to all Core files</description>
4
5        <!--
6        #############################################################################
7        COMMAND LINE ARGUMENTS
8        https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
9        #############################################################################
10        -->
11
12        <!-- Only scan PHP files. -->
13        <arg name="extensions" value="php"/>
14
15        <!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
16        <arg name="cache" value=".cache/phpcs.json"/>
17
18        <!-- Set the memory limit to 512M.
19                 For most standard PHP configurations, this means the memory limit will temporarily be raised.
20                 Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#specifying-phpini-settings
21        -->
22        <ini name="memory_limit" value="512M"/>
23
24        <!-- Strip the filepaths down to the relevant bit. -->
25        <arg name="basepath" value="./"/>
26
27        <!-- Check up to 20 files simultaneously. -->
28        <arg name="parallel" value="20"/>
29
30        <!-- Show sniff codes in all reports. -->
31        <arg value="ps"/>
32
33        <!--
34        #############################################################################
35        FILE SELECTION
36        Set which files will be subject to the scans executed using this ruleset.
37        #############################################################################
38        -->
39
40        <file>.</file>
41
42        <!-- Exclude the build folder in the current directory. -->
43        <exclude-pattern type="relative">^build/*</exclude-pattern>
44
45        <!-- Directories and third party library exclusions. -->
46        <exclude-pattern>/node_modules/*</exclude-pattern>
47        <exclude-pattern>/vendor/*</exclude-pattern>
48
49        <exclude-pattern>/src/wp-admin/includes/class-ftp*</exclude-pattern>
50        <exclude-pattern>/src/wp-admin/includes/class-pclzip\.php</exclude-pattern>
51        <exclude-pattern>/src/wp-admin/includes/deprecated\.php</exclude-pattern>
52        <exclude-pattern>/src/wp-admin/includes/ms-deprecated\.php</exclude-pattern>
53
54        <exclude-pattern>/src/wp-includes/atomlib\.php</exclude-pattern>
55        <exclude-pattern>/src/wp-includes/class-avif-info\.php</exclude-pattern>
56        <exclude-pattern>/src/wp-includes/class-IXR\.php</exclude-pattern>
57        <exclude-pattern>/src/wp-includes/class-json\.php</exclude-pattern>
58        <exclude-pattern>/src/wp-includes/class-phpass\.php</exclude-pattern>
59        <exclude-pattern>/src/wp-includes/class-pop3\.php</exclude-pattern>
60        <exclude-pattern>/src/wp-includes/class-requests\.php</exclude-pattern>
61        <exclude-pattern>/src/wp-includes/class-simplepie\.php</exclude-pattern>
62        <exclude-pattern>/src/wp-includes/class-snoopy\.php</exclude-pattern>
63        <exclude-pattern>/src/wp-includes/deprecated\.php</exclude-pattern>
64        <exclude-pattern>/src/wp-includes/ms-deprecated\.php</exclude-pattern>
65        <exclude-pattern>/src/wp-includes/pluggable-deprecated\.php</exclude-pattern>
66        <exclude-pattern>/src/wp-includes/rss\.php</exclude-pattern>
67
68        <exclude-pattern>/src/wp-includes/assets/*</exclude-pattern>
69        <exclude-pattern>/src/wp-includes/blocks/*/*.asset.php</exclude-pattern>
70        <exclude-pattern>/src/wp-includes/blocks/blocks-json.php</exclude-pattern>
71        <exclude-pattern>/src/wp-includes/ID3/*</exclude-pattern>
72        <exclude-pattern>/src/wp-includes/IXR/*</exclude-pattern>
73        <exclude-pattern>/src/wp-includes/js/*</exclude-pattern>
74        <exclude-pattern>/src/wp-includes/PHPMailer/*</exclude-pattern>
75        <exclude-pattern>/src/wp-includes/Requests/*</exclude-pattern>
76        <exclude-pattern>/src/wp-includes/SimplePie/*</exclude-pattern>
77        <exclude-pattern>/src/wp-includes/sodium_compat/*</exclude-pattern>
78        <exclude-pattern>/src/wp-includes/Text/*</exclude-pattern>
79
80        <!-- Test data and fixtures. -->
81        <exclude-pattern>/tests/phpunit/build*</exclude-pattern>
82        <exclude-pattern>/tests/phpunit/data/*</exclude-pattern>
83
84        <exclude-pattern>/tools/*</exclude-pattern>
85
86        <!-- Drop-in plugins. -->
87        <exclude-pattern>/src/wp-content/advanced-cache\.php</exclude-pattern>
88        <exclude-pattern>/src/wp-content/blog-deleted\.php</exclude-pattern>
89        <exclude-pattern>/src/wp-content/blog-inactive\.php</exclude-pattern>
90        <exclude-pattern>/src/wp-content/blog-suspended\.php</exclude-pattern>
91        <exclude-pattern>/src/wp-content/db-error\.php</exclude-pattern>
92        <exclude-pattern>/src/wp-content/db\.php</exclude-pattern>
93        <exclude-pattern>/src/wp-content/fatal-error-handler\.php</exclude-pattern>
94        <exclude-pattern>/src/wp-content/install\.php</exclude-pattern>
95        <exclude-pattern>/src/wp-content/maintenance\.php</exclude-pattern>
96        <exclude-pattern>/src/wp-content/object-cache\.php</exclude-pattern>
97        <exclude-pattern>/src/wp-content/php-error\.php</exclude-pattern>
98        <exclude-pattern>/src/wp-content/sunrise\.php</exclude-pattern>
99
100        <!-- Must-Use plugins. -->
101        <exclude-pattern>/src/wp-content/mu-plugins/*</exclude-pattern>
102
103        <!-- Plugins. -->
104        <exclude-pattern>/src/wp-content/plugins/*</exclude-pattern>
105
106        <!-- Themes except the twenty* themes. -->
107        <exclude-pattern>/src/wp-content/themes/(?!twenty)*</exclude-pattern>
108
109        <!-- Translation files. -->
110        <exclude-pattern>/src/wp-content/languages/*</exclude-pattern>
111
112
113        <!--
114        #############################################################################
115        SET UP THE RULESET
116        #############################################################################
117        -->
118
119        <rule ref="WordPress-Core"/>
120
121
122        <!--
123        #############################################################################
124        SNIFF-SPECIFIC CONFIGURATION
125        #############################################################################
126        -->
127
128        <!-- These rules are being set as warnings instead of errors, so we can error check the entire codebase. -->
129        <rule ref="Generic.Files.OneObjectStructurePerFile.MultipleFound">
130                <type>warning</type>
131                <!-- Exclude the unit tests as no warnings are allowed there. Note: these issues should be fixed and the exclude removed! -->
132                <exclude-pattern>/tests/phpunit/*</exclude-pattern>
133        </rule>
134        <rule ref="WordPress.DB.PreparedSQL.InterpolatedNotPrepared">
135                <type>warning</type>
136        </rule>
137        <rule ref="WordPress.DB.PreparedSQL.NotPrepared">
138                <type>warning</type>
139        </rule>
140        <rule ref="WordPress.Files.FileName.InvalidClassFileName">
141                <type>warning</type>
142        </rule>
143        <rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
144                <type>warning</type>
145        </rule>
146
147        <rule ref="WordPress.NamingConventions.ValidVariableName">
148                <properties>
149                        <property name="allowed_custom_properties" type="array">
150                                <!-- From database structure queries. -->
151                                <element value="Collation"/>
152                                <element value="Column_name"/>
153                                <element value="Default"/>
154                                <element value="Extra"/>
155                                <element value="Field"/>
156                                <element value="Index_type"/>
157                                <element value="Key"/>
158                                <element value="Key_name"/>
159                                <element value="Msg_text"/>
160                                <element value="Non_unique"/>
161                                <element value="Null"/>
162                                <element value="Sub_part"/>
163                                <element value="Type"/>
164                                <!-- From plugin/theme data. -->
165                                <element value="authorAndUri"/>
166                                <element value="Name"/>
167                                <element value="Version"/>
168                                <!-- From the result of wp_xmlrpc_server::wp_getPageList(). -->
169                                <element value="dateCreated"/>
170
171                                <!-- From DOMDocument. -->
172                                <element value="childNodes"/>
173                                <element value="firstChild"/>
174                                <element value="formatOutput"/>
175                                <element value="lastChild"/>
176                                <element value="nodeName"/>
177                                <element value="nodeType"/>
178                                <element value="nodeValue"/>
179                                <element value="parentNode"/>
180                                <element value="preserveWhiteSpace"/>
181                                <element value="textContent"/>
182                                <!-- From PHPMailer. -->
183                                <element value="AltBody"/>
184                                <element value="Body"/>
185                                <element value="CharSet"/>
186                                <element value="ContentType"/>
187                                <element value="Encoding"/>
188                                <element value="Hostname"/>
189                                <element value="mailHeader"/>
190                                <element value="MIMEBody"/>
191                                <element value="MIMEHeader"/>
192                                <element value="Sender"/>
193                                <element value="Subject"/>
194                                <!-- From PHPUnit_Util_Getopt. -->
195                                <element value="longOptions"/>
196                                <!-- From POP3. -->
197                                <element value="ERROR"/>
198                                <!-- From ZipArchive. -->
199                                <element value="numFiles"/>
200                        </property>
201                </properties>
202        </rule>
203
204        <rule ref="WordPress.PHP.NoSilencedErrors">
205                <properties>
206                        <property name="customAllowedFunctionsList" type="array">
207                                <element value="ssh2_connect"/>
208                                <element value="ssh2_auth_password"/>
209                                <element value="ssh2_auth_pubkey_file"/>
210                                <element value="ftp_ssl_connect"/>
211                                <element value="ftp_connect"/>
212                                <element value="ftp_get_option"/>
213                                <element value="ftp_set_option"/>
214                                <element value="disk_free_space"/>
215                                <element value="getimagesize"/>
216                                <element value="iptcparse"/>
217                                <element value="exif_read_data"/>
218                                <element value="gzinflate"/>
219                                <element value="gzuncompress"/>
220                                <element value="gzdecode"/>
221                                <element value="imagecreatefromwebp"/>
222                                <element value="imagecreatefromavif"/>
223                        </property>
224                </properties>
225        </rule>
226
227
228        <!--
229        #############################################################################
230        SELECTIVE EXCLUSIONS
231        Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
232       
233        These exclusions are listed ordered by alphabetic sniff name.
234        #############################################################################
235        -->
236
237        <!-- Assignments in while conditions are a valid method of looping over iterables. -->
238        <rule ref="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition">
239                <exclude-pattern>*</exclude-pattern>
240        </rule>
241
242        <!-- Exclude checking of line endings when reporting errors, but fix them when running phpcbf.
243                 Git and SVN manage these pretty well cross-platform as "native".
244                 Allow configuration files. -->
245        <rule ref="Generic.Files.LineEndings">
246                <exclude-pattern>/wp-config\.php</exclude-pattern>
247                <exclude-pattern>/wp-config-sample\.php</exclude-pattern>
248                <exclude phpcs-only="true" name="Generic.Files.LineEndings"/>
249        </rule>
250
251        <rule ref="Generic.Functions.FunctionCallArgumentSpacing">
252                <exclude-pattern>/wp-config\.php</exclude-pattern>
253                <exclude-pattern>/wp-config-sample\.php</exclude-pattern>
254                <exclude-pattern>/wp-tests-config\.php</exclude-pattern>
255                <exclude-pattern>/wp-tests-config-sample\.php</exclude-pattern>
256        </rule>
257
258        <!-- Exclude forbidding goto in the HTML Processor, which mimics algorithms that are written
259             this way in the HTML specification, and these particular algorithms are complex and
260             highly imperative. Avoiding the goto introduces a number of risks that could make it
261             more difficult to maintain the relationship to the standard, lead to subtle differences
262             in the parsing, and distance the code from its standard. -->
263        <rule ref="Generic.PHP.DiscourageGoto.Found">
264                <exclude-pattern>/wp-includes/html-api/class-wp-html-processor\.php</exclude-pattern>
265                <exclude-pattern>/wp-includes/html-api/class-wp-html-doctype-info\.php</exclude-pattern>
266        </rule>
267
268        <!-- Exclude sample config from modernization to prevent breaking CI workflows based on WP-CLI scaffold.
269                 See: https://core.trac.wordpress.org/ticket/48082#comment:16 -->
270        <rule ref="Modernize.FunctionCalls.Dirname.FileConstant">
271                <exclude-pattern>/wp-tests-config-sample\.php</exclude-pattern>
272        </rule>
273
274        <rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
275                <exclude-pattern>/tests/phpunit/tests/*</exclude-pattern>
276                <!-- Exclude some old classes that cannot be renamed, as it would break back compat. -->
277                <exclude-pattern>/src/wp-admin/includes/class-wp-filesystem-ftpsockets\.php</exclude-pattern>
278                <exclude-pattern>/src/wp-includes/class-wp-oembed\.php</exclude-pattern>
279                <exclude-pattern>/src/wp-includes/class-wp-oembed-controller\.php</exclude-pattern>
280                <exclude-pattern>/src/wp-includes/class-wp-xmlrpc-server\.php</exclude-pattern>
281                <exclude-pattern>/src/wp-includes/class-wp-text-diff-renderer-inline\.php</exclude-pattern>
282        </rule>
283
284        <!-- Exclude some old classes that cannot be renamed, as it would break back compat. -->
285        <rule ref="PEAR.NamingConventions.ValidClassName.StartWithCapital">
286                <exclude-pattern>/src/wp-admin/includes/class-wp-list-table-compat\.php</exclude-pattern>
287                <exclude-pattern>/src/wp-includes/class-wp-dependency\.php</exclude-pattern>
288                <exclude-pattern>/src/wp-includes/class-wp-editor\.php</exclude-pattern>
289                <exclude-pattern>/src/wp-includes/class-wp-xmlrpc-server\.php</exclude-pattern>
290                <exclude-pattern>/src/wp-includes/class-wpdb\.php</exclude-pattern>
291        </rule>
292
293        <!-- Allow the WP DB Class and related tests for usage of direct database access functions. -->
294        <rule ref="WordPress.DB.RestrictedFunctions">
295                <exclude-pattern>/src/wp-includes/class-wpdb\.php</exclude-pattern>
296                <exclude-pattern>/tests/phpunit/tests/db/charset\.php</exclude-pattern>
297        </rule>
298
299        <!-- Allow the WP DB related tests for issues with prepared SQL placeholders
300                 (as the handling of those are being tested). -->
301        <rule ref="WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare">
302                <exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern>
303        </rule>
304        <rule ref="WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder">
305                <exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern>
306        </rule>
307        <rule ref="WordPress.DB.PreparedSQLPlaceholders.UnescapedLiteral">
308                <exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern>
309        </rule>
310        <rule ref="WordPress.DB.PreparedSQL.NotPrepared">
311                <exclude-pattern>/tests/phpunit/tests/admin/includesSchema\.php</exclude-pattern>
312                <exclude-pattern>/tests/phpunit/tests/multisite/site\.php</exclude-pattern>
313        </rule>
314
315        <!-- Exclude the unit tests from the file name rules. -->
316        <rule ref="WordPress.Files.FileName">
317                <exclude-pattern>/tests/phpunit/*</exclude-pattern>
318        </rule>
319
320        <!-- WPCS1620: template.php isn't a template tag file. -->
321        <rule ref="WordPress.Files.FileName.InvalidTemplateTagFileName">
322                <exclude-pattern>/src/wp-includes/template\.php</exclude-pattern>
323        </rule>
324
325        <!-- Exclude some incorrectly named files that won't be renamed. -->
326        <rule ref="WordPress.Files.FileName.InvalidClassFileName">
327                <exclude-pattern>/src/wp-admin/includes/class-wp-list-table-compat\.php</exclude-pattern>
328                <exclude-pattern>/src/wp-includes/class-wp-dependency\.php</exclude-pattern>
329                <exclude-pattern>/src/wp-includes/class-wp-editor\.php</exclude-pattern>
330                <exclude-pattern>/src/wp-content/themes/twentyeleven/inc/widgets\.php</exclude-pattern>
331                <exclude-pattern>/src/wp-content/themes/twentyfourteen/inc/widgets\.php</exclude-pattern>
332                <exclude-pattern>/src/wp-content/themes/twentyfourteen/inc/featured-content\.php</exclude-pattern>
333        </rule>
334
335        <!-- WPCS1621: These files are expected to use _ instead of -. -->
336        <rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
337                <exclude-pattern>/src/_index\.php</exclude-pattern>
338                <exclude-pattern>/src/wp-admin/_index\.php</exclude-pattern>
339                <exclude-pattern>/src/wp-content/themes/twentythirteen/taxonomy-post_format\.php</exclude-pattern>
340                <exclude-pattern>/src/wp-content/themes/twentyfourteen/taxonomy-post_format\.php</exclude-pattern>
341        </rule>
342
343        <!-- Allow the I18n functions file for issues identified by the I18n sniff
344                 (such as calling the low-level translate() function). -->
345        <rule ref="WordPress.WP.I18n">
346                <exclude-pattern>/src/wp-includes/l10n\.php</exclude-pattern>
347                <exclude-pattern>/tests/phpunit/tests/l10n\.php</exclude-pattern>
348                <exclude-pattern>/tests/phpunit/tests/l10n/loadTextdomainJustInTime\.php</exclude-pattern>
349        </rule>
350
351        <!-- Translator comments aren't needed in unit tests. -->
352        <rule ref="WordPress.WP.I18n.MissingTranslatorsComment">
353                <exclude-pattern>/tests/*</exclude-pattern>
354        </rule>
355
356</ruleset>
Note: See TracBrowser for help on using the repository browser.