Make WordPress Core

Changeset 56695 for trunk/phpcs.xml.dist

09/26/2023 12:24:43 AM (8 months ago)

Coding Standards: Upgrade WPCS to version 3.0.0.

This is an important release which makes significant changes to improve the accuracy, performance, stability and maintainability of all sniffs, as well as making WordPressCS much better at handling modern PHP.

WordPressCS 3.0.0 contains breaking changes, both for people using ignore annotations, people maintaining custom rulesets, as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS.

If you are an end-user or maintain a custom WordPressCS based ruleset, please start by reading the Upgrade Guide to WordPressCS 3.0.0 for ruleset maintainers which lists the most important changes and contains a step by step guide for upgrading.

If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WordPressCS sniffs, please read the Upgrade Guide to WordPressCS 3.0.0 for Developers.

In all cases, please read the complete changelog carefully before you upgrade.

This commit:

  • Updates the Composer dependencies to use the new version, including updating the underlying PHP_CodeSniffer dependency to the new minimum supported version for WPCS.
    Note: the Composer PHPCS installer plugin is no longer explicitly required as it is now a dependency of WPCS, so the dependency is inherited automatically.
  • Updates the ruleset for WPCS 3.0.0. This includes:
    • Raising the memory limit to be on the safe side as WPCS 3.0.0 contains a lot more sniffs.
    • Removing explicit inclusions of extra rules, which have now been added to the WordPress-Core ruleset..
    • Updating property names for select sniffs.
    • Updating one exclusion — the WordPress.CodeAnalysis.AssignmentInCondition sniff has been (partially) replaced by the Generic.CodeAnalysis.AssignmentInCondition sniff.
    • Adding one new exclusion.
  • Downgrades one new error to a warning.
    The Generic.Files.OneObjectStructurePerFile sniff enforces that there is only one OO structure declaration per file. At this time, this sniff would yield 29 errors. By downgrading the sniff to a warning, the build can pass and the issues can be fixed in due time. For now, the test directory will be excluded until the issues are fixed (as the test directory CS run does not allow for warnings).
  • Updates ignore annotations for WPCS 3.0.0.

Reference: WPCS 3.0.0 release notes.

Follow-up to [43571], [44574], [45600], [47927].

Props jrf, jorbin, desrosj.
See #59161.

1 edited


  • trunk/phpcs.xml.dist

    r56669 r56695  
    1616    <arg name="cache" value=".cache/phpcs.json"/>
    18     <!-- Set the memory limit to 256M.
     18    <!-- Set the memory limit to 512M.
    1919         For most standard PHP configurations, this means the memory limit will temporarily be raised.
    2020         Ref:
    2121    -->
    22     <ini name="memory_limit" value="256M"/>
     22    <ini name="memory_limit" value="512M"/>
    2424    <!-- Strip the filepaths down to the relevant bit. -->
    115115    <rule ref="WordPress-Core"/>
    116     <rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
    118     <!-- Enforce no parenthesis for language constructs, and only one space immediately after.
    119          Including this rule is temporary until it is moved from the WordPress-Extra ruleset to
    120          the WordPress-Core ruleset upstream.
    121     -->
    122     <rule ref="PEAR.Files.IncludingFile.BracketsNotRequired">
    123         <type>warning</type>
    124     </rule>
    125     <rule ref="PEAR.Files.IncludingFile.UseRequire">
    126         <type>warning</type>
    127     </rule>
    128     <rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
    129         <type>warning</type>
    130     </rule>
    131     <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
    140124    <!-- These rules are being set as warnings instead of errors, so we can error check the entire codebase. -->
     125    <rule ref="Generic.Files.OneObjectStructurePerFile.MultipleFound">
     126        <type>warning</type>
     127        <!-- Exclude the unit tests as no warnings are allowed there. Note: these issues should be fixed and the exclude removed! -->
     128        <exclude-pattern>/tests/phpunit/*</exclude-pattern>
     129    </rule>
    141130    <rule ref="WordPress.DB.PreparedSQL.InterpolatedNotPrepared">
    142131        <type>warning</type>
    154143    <rule ref="WordPress.NamingConventions.ValidVariableName">
    155144        <properties>
    156             <property name="customPropertiesWhitelist" type="array">
     145            <property name="allowed_custom_properties" type="array">
    157146                <!-- From database structure queries. -->
    158147                <element value="Collation"/>
    210199    <rule ref="WordPress.PHP.NoSilencedErrors">
    211200        <properties>
    212             <property name="custom_whitelist" type="array">
     201            <property name="customAllowedFunctionsList" type="array">
    213202                <element value="ssh2_connect"/>
    214203                <element value="ssh2_auth_password"/>
    240229    -->
     231    <!-- Assignments in while conditions are a valid method of looping over iterables. -->
     232    <rule ref="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition">
     233        <exclude-pattern>*</exclude-pattern>
     234    </rule>
    242236    <!-- Exclude checking of line endings when reporting errors, but fix them when running phpcbf.
    243237         Git and SVN manage these pretty well cross-platform as "native".
    253247        <exclude-pattern>/wp-config-sample\.php</exclude-pattern>
    254248        <exclude-pattern>/wp-tests-config\.php</exclude-pattern>
     249        <exclude-pattern>/wp-tests-config-sample\.php</exclude-pattern>
     250    </rule>
     252    <!-- Exclude sample config from modernization to prevent breaking CI workflows based on WP-CLI scaffold.
     253         See: -->
     254    <rule ref="Modernize.FunctionCalls.Dirname.FileConstant">
    255255        <exclude-pattern>/wp-tests-config-sample\.php</exclude-pattern>
    256256    </rule>
    275275    </rule>
    277     <!-- Assignments in while conditions are a valid method of looping over iterables. -->
    278     <rule ref="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition">
    279         <exclude-pattern>*</exclude-pattern>
     277    <!-- Temporarily ignore this sniff for block files until the changes from upstream make it into core.
     278         This can be removed once the block-library package is updated for WP 6.4. -->
     279    <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction">
     280        <exclude-pattern>/src/wp-includes/blocks/*</exclude-pattern>
    280281    </rule>
Note: See TracChangeset for help on using the changeset viewer.