2011-07-18 00:15:41 +01:00
|
|
|
<?xml version="1.0"?>
|
2025-05-19 18:23:15 +02:00
|
|
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Example Project" xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd">
|
Rulesets: Add XSD schema tags and validate rulesets against schema (PHPCS 3.2+/3.3.2+)
As of PHPCS 3.2.0, PHPCS includes an XSD schema for rulesets which defines what can be used in the XML ruleset file.
In PHPCS 3.3.0 a new array format for properties was introduced and as of PHPCS 3.3.2, the new array format is now also covered by this schema.
This commit:
* Adds the schema tags to the `ruleset.xml` files, the WPCS native `.phpcs.xml.dist` file, as well as to the example ruleset.
* Adds validation against the schema for the `ruleset.xml` files and the example ruleset to the Travis build.
Note:
The schema used in the tags points to the online schema in PHPCS `master` for two reasons:
1. While WPCS now has a minimum requirement of PHPCS 3.3.1, the schema in PHPCS `master` contains the changes which were made in PHPCS 3.3.2, so we can safely validate the rulesets against the schema.
2. While installation via Composer is supported for WPCS, it is **not** the _only_ supported installation method, so pointing to the version of the XSD schema in the `vendor` directory would be presumptuous.
At the same time, using the URL in the Travis script appears to be problematic and as we're doing a composer install there anyway, we may as well use the version in the `vendor` directory for the actual validation.
As the validation is done on a build with PHPCS `master`, there will be no difference anyway.
Fixes 1477
2018-12-16 14:49:45 +01:00
|
|
|
|
2012-04-23 20:34:04 +10:00
|
|
|
<description>A custom set of rules to check for a WPized WordPress project</description>
|
2011-07-18 00:15:41 +01:00
|
|
|
|
2022-12-04 18:04:43 +01:00
|
|
|
<!--
|
|
|
|
#############################################################################
|
|
|
|
COMMAND LINE ARGUMENTS
|
2023-11-07 01:11:00 +01:00
|
|
|
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
|
2022-12-04 18:04:43 +01:00
|
|
|
#############################################################################
|
|
|
|
-->
|
|
|
|
|
2022-12-04 18:05:05 +01:00
|
|
|
<file>.</file>
|
|
|
|
|
2017-07-14 03:57:27 +02:00
|
|
|
<!-- Exclude WP Core folders and files from being checked. -->
|
2012-04-23 20:34:04 +10:00
|
|
|
<exclude-pattern>/docroot/wp-admin/*</exclude-pattern>
|
|
|
|
<exclude-pattern>/docroot/wp-includes/*</exclude-pattern>
|
|
|
|
<exclude-pattern>/docroot/wp-*.php</exclude-pattern>
|
|
|
|
<exclude-pattern>/docroot/index.php</exclude-pattern>
|
|
|
|
<exclude-pattern>/docroot/xmlrpc.php</exclude-pattern>
|
|
|
|
<exclude-pattern>/docroot/wp-content/plugins/*</exclude-pattern>
|
2011-07-18 00:15:41 +01:00
|
|
|
|
2017-06-30 00:22:23 +02:00
|
|
|
<!-- Exclude the Composer Vendor directory. -->
|
2017-04-05 16:55:20 +02:00
|
|
|
<exclude-pattern>/vendor/*</exclude-pattern>
|
2011-07-18 00:15:41 +01:00
|
|
|
|
2017-07-14 03:57:27 +02:00
|
|
|
<!-- Exclude the Node Modules directory. -->
|
|
|
|
<exclude-pattern>/node_modules/*</exclude-pattern>
|
|
|
|
|
|
|
|
<!-- Exclude minified Javascript files. -->
|
|
|
|
<exclude-pattern>*.min.js</exclude-pattern>
|
|
|
|
|
2022-12-04 18:05:05 +01:00
|
|
|
<!-- Strip the filepaths down to the relevant bit. -->
|
|
|
|
<arg name="basepath" value="."/>
|
|
|
|
|
|
|
|
<!-- Check up to 8 files simultaneously. -->
|
|
|
|
<arg name="parallel" value="8"/>
|
|
|
|
|
2022-12-04 18:04:43 +01:00
|
|
|
|
|
|
|
<!--
|
|
|
|
#############################################################################
|
|
|
|
SET UP THE RULESETS
|
|
|
|
#############################################################################
|
|
|
|
-->
|
|
|
|
|
2017-06-30 00:22:23 +02:00
|
|
|
<!-- Include the WordPress-Extra standard. -->
|
2017-04-05 16:55:20 +02:00
|
|
|
<rule ref="WordPress-Extra">
|
2012-04-23 20:34:04 +10:00
|
|
|
<!--
|
|
|
|
We may want a middle ground though. The best way to do this is add the
|
2017-04-05 16:55:20 +02:00
|
|
|
entire ruleset, then rule by rule, remove ones that don't suit a project.
|
2017-06-30 00:22:23 +02:00
|
|
|
We can do this by running `phpcs` with the '-s' flag, which allows us to
|
|
|
|
see the names of the sniffs reporting errors.
|
|
|
|
Once we know the sniff names, we can opt to exclude sniffs which don't
|
|
|
|
suit our project like so.
|
2017-09-08 15:16:41 +02:00
|
|
|
|
2022-11-26 14:41:00 +01:00
|
|
|
The below two examples just show how you can exclude rules/error codes.
|
2017-09-08 15:16:41 +02:00
|
|
|
They are not intended as advice about which sniffs to exclude.
|
2012-04-23 20:34:04 +10:00
|
|
|
-->
|
2011-07-18 00:15:41 +01:00
|
|
|
|
2017-09-08 15:16:41 +02:00
|
|
|
<!--
|
2017-04-05 04:21:53 +02:00
|
|
|
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
|
2022-11-26 14:41:00 +01:00
|
|
|
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/>
|
2017-09-08 15:16:41 +02:00
|
|
|
-->
|
2012-04-23 20:34:04 +10:00
|
|
|
</rule>
|
2017-04-05 16:55:20 +02:00
|
|
|
|
|
|
|
<!-- Let's also check that everything is properly documented. -->
|
|
|
|
<rule ref="WordPress-Docs"/>
|
|
|
|
|
|
|
|
<!-- Add in some extra rules from other standards. -->
|
|
|
|
<rule ref="Generic.Commenting.Todo"/>
|
|
|
|
|
|
|
|
<!-- Check for PHP cross-version compatibility. -->
|
|
|
|
<!--
|
2018-10-08 02:03:39 +02:00
|
|
|
To enable this, the PHPCompatibilityWP standard needs
|
2017-04-05 16:55:20 +02:00
|
|
|
to be installed.
|
|
|
|
See the readme for installation instructions:
|
2018-10-08 02:03:39 +02:00
|
|
|
https://github.com/PHPCompatibility/PHPCompatibilityWP
|
|
|
|
For more information, also see:
|
|
|
|
https://github.com/PHPCompatibility/PHPCompatibility
|
2017-04-05 16:55:20 +02:00
|
|
|
-->
|
|
|
|
<!--
|
2022-11-26 14:41:00 +01:00
|
|
|
<config name="testVersion" value="5.6-"/>
|
|
|
|
<rule ref="PHPCompatibilityWP">
|
|
|
|
<include-pattern>*\.php</include-pattern>
|
|
|
|
</rule>
|
2017-04-05 16:55:20 +02:00
|
|
|
-->
|
|
|
|
|
2022-12-04 18:04:43 +01:00
|
|
|
|
|
|
|
<!--
|
|
|
|
#############################################################################
|
|
|
|
SNIFF SPECIFIC CONFIGURATION
|
|
|
|
#############################################################################
|
|
|
|
-->
|
|
|
|
|
2017-04-05 16:55:20 +02:00
|
|
|
<!--
|
2022-11-26 14:41:00 +01:00
|
|
|
To get the optimal benefits of using WordPressCS, we should add a couple of
|
2017-04-05 16:55:20 +02:00
|
|
|
custom properties.
|
|
|
|
Adjust the values of these properties to fit our needs.
|
|
|
|
|
|
|
|
For information on additional custom properties available, check out
|
|
|
|
the wiki:
|
2019-07-01 05:33:31 +02:00
|
|
|
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
|
2017-04-05 16:55:20 +02:00
|
|
|
-->
|
2022-11-26 14:41:00 +01:00
|
|
|
<config name="minimum_wp_version" value="6.0"/>
|
2017-09-23 14:19:03 +02:00
|
|
|
|
2017-04-05 16:55:20 +02:00
|
|
|
<rule ref="WordPress.WP.I18n">
|
|
|
|
<properties>
|
2018-12-16 15:03:45 +01:00
|
|
|
<property name="text_domain" type="array">
|
|
|
|
<element value="my-textdomain"/>
|
|
|
|
<element value="library-textdomain"/>
|
|
|
|
</property>
|
2017-04-05 16:55:20 +02:00
|
|
|
</properties>
|
|
|
|
</rule>
|
|
|
|
|
|
|
|
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
|
|
|
|
<properties>
|
2018-12-16 15:03:45 +01:00
|
|
|
<property name="prefixes" type="array">
|
|
|
|
<element value="my_prefix"/>
|
|
|
|
</property>
|
2017-04-05 16:55:20 +02:00
|
|
|
</properties>
|
|
|
|
</rule>
|
|
|
|
|
2022-11-26 14:41:00 +01:00
|
|
|
|
|
|
|
<!--
|
|
|
|
#############################################################################
|
|
|
|
SELECTIVE EXCLUSIONS
|
|
|
|
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
|
|
|
|
#############################################################################
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!--
|
|
|
|
Sometimes, you may want to exclude a certain directory, like your tests,
|
|
|
|
for select sniffs.
|
|
|
|
The below examples demonstrate how to do this.
|
|
|
|
|
|
|
|
In the example, the `GlobalVariablesOverride` rule is excluded for test files
|
|
|
|
as it is sometimes necessary to overwrite WP globals in test situations (just
|
|
|
|
don't forget to restore them after the test!).
|
|
|
|
|
|
|
|
Along the same lines, PHPUnit is getting stricter about using PSR-4 file names,
|
|
|
|
so excluding test files from the `WordPress.Files.Filename` sniff can be a
|
|
|
|
legitimate exclusion.
|
|
|
|
|
2024-08-07 12:30:25 +02:00
|
|
|
For more information on ruleset configuration options, check out the PHPCS wiki:
|
2023-11-07 01:11:00 +01:00
|
|
|
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
|
2022-11-26 14:41:00 +01:00
|
|
|
-->
|
|
|
|
<rule ref="WordPress.WP.GlobalVariablesOverride">
|
|
|
|
<exclude-pattern>/path/to/Tests/*Test\.php</exclude-pattern>
|
|
|
|
</rule>
|
2023-09-03 10:43:53 +02:00
|
|
|
<rule ref="WordPress.Files.FileName">
|
2022-11-26 14:41:00 +01:00
|
|
|
<exclude-pattern>/path/to/Tests/*Test\.php</exclude-pattern>
|
|
|
|
</rule>
|
|
|
|
|
2011-07-18 00:15:41 +01:00
|
|
|
</ruleset>
|