WordPress-Coding-Standards/.phpcs.xml.dist
jrfnl f672e18007 Travis/PHPCS: check WPCS own code for PHP cross-version compatibility
As the code in WPCS itself should be compatible with PHP 5.3 - nightly, why not let the PHPCompatibility standard check this for us ?

Composer:
* Adds `require-dev` section to `composer.json`.
* Adds install path for PHPCompatibility to the default script.
    This is only run when WPCS is installed from the root, so only relevant for devs, so adding PHPCompatibility there can be considered "safe".
    Note: PHPCS will complain if it is run with this installed path if PHPCompatibility is not installed, i.e. if Composer was run from root with `--no-dev`.

Travis:
* Switches over the Travis script to use Composer to install the dependencies.
    - As the bootstraps are already coded to pick up PHPCS when installed in the `vendor` directory, no need for the `PHPCS_DIR` variable anymore.
    - As the `phpcs` executable will always be in the `vendor/bin/` directory, no need for the `PHPCS_BIN` variable anymore.
    - `--(update-)no-dev` is used as for the unit test runs, we don't need PHPCompatibility for those.
    - For PHPCS 2.x installing with `--prefer-source` is needed as otherwise the unit tests base files we need are not included in the install.
    - `--no-scripts` is used as the script in the `composer.json` file presumes PHPCompatibility, while for most builds it will not be available.
    - For the non-sniff runs, the `installed_paths` command is run. For the sniff-run, a` composer install` (with `dev`) is run which will let the `post-install-cmd` run this for us.
* Adjusted the `PHP_BRANCH` environment variable values to be usable by Composer.
* Excludes the `vendor` directory from the PHP lint check in the Travis script.

WPCS own ruleset:
* Adds the PHPCompatibility standard, set the `testVersion` and exclude errors for PHP native constants which are back-filled by PHPCS.

Includes one `phpcs:ignore` for a correctly used function which is not always available.
2018-07-05 20:49:40 +02:00

54 lines
2.1 KiB
XML

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<description>The Coding standard for the WordPress Coding Standards itself.</description>
<file>.</file>
<arg value="sp"/>
<arg name="extensions" value="php"/>
<!-- Exclude the code in the PHPCS 2.x test files copied in from PHPCS. -->
<exclude-pattern>/Test/AllTests.php</exclude-pattern>
<exclude-pattern>/Test/Standards/*.php</exclude-pattern>
<!-- Exclude Composer vendor directory. -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<rule ref="WordPress-Extra">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
</rule>
<rule ref="WordPress-Docs"/>
<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<property name="alignMultilineItems" value="!=100"/>
</properties>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<!-- Check code for cross-version PHP compatibility. -->
<config name="testVersion" value="5.3-"/>
<rule ref="PHPCompatibility">
<!-- Exclude PHP constants back-filled by PHPCS. -->
<exclude name="PHPCompatibility.PHP.NewConstants.t_finallyFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_yieldFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_ellipsisFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_powFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_pow_equalFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_spaceshipFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_coalesceFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_coalesce_equalFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.t_yield_fromFound"/>
<!-- Unclear how, but appears to be back-filled anyhow, could be that PHP did so before the token was in use. -->
<exclude name="PHPCompatibility.PHP.NewConstants.t_traitFound"/>
</rule>
</ruleset>