PHPCompatibility / PHPCompatibility

PHP Compatibility check for PHP_CodeSniffer
http://techblog.wimgodden.be/tag/codesniffer/
GNU Lesser General Public License v3.0
2.17k stars 193 forks source link

Referenced sniff "PHPCompatibility.PHP.RemovedExtensions" does not exist #1718

Closed kingkool68 closed 4 months ago

kingkool68 commented 4 months ago

Bug Description

I copied my composer.json contents from one project to another and for some reason I keep getting this error when trying to sniff my codebase using the PHP Sniffer & Beautifier VSCode extension.

Given the following reproduction Scenario

composer.json:

{
    "name": "kingkool68/whatever",
    "description": "Whatever",
    "require": {
        "php": "^8.2"
    },
    "require-dev": {
        "phpcompatibility/phpcompatibility-wp": "*",
        "wp-coding-standards/wpcs": "^3.0.0",
        "php-stubs/wordpress-stubs": "^6.0",
        "php-stubs/acf-pro-stubs": "^6.0"
    },
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    }
}

The issue happens when running this command:

phpcs -ps file.php --standard=PHPCompatibility --runtime-set testVersion #.#-

... over a file containing this code:

// Place your code sample here.

... with this custom ruleset:

<?xml version="1.0"?>
<ruleset name="whatever">
    <!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
    <!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->

    <!-- Set a description for this ruleset. -->
    <description>A custom set of code standard rules to check for WordPress themes.</description>

    <file>.</file>
    <exclude-pattern>node_modules/*</exclude-pattern>
    <exclude-pattern>vendor/*</exclude-pattern>
    <exclude-pattern>*.js</exclude-pattern>
    <exclude-pattern>*.css</exclude-pattern>

    <!-- Include the WordPress ruleset, with exclusions. -->
    <rule ref="WordPress">
        <!-- File comments are optional -->
        <exclude name="Squiz.Commenting.FileComment.Missing"/>
        <!-- It's ok if comments don't end in a full stop -->
        <exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
        <exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
        <!-- It's ok if @throws doc block tag doesn't end in a full stop -->
        <exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop"/>
        <exclude name="Generic.Commenting.DocComment.LongNotCapital"/>
        <!-- We automatically handle static asset versioning based on when the file was last modified -->
        <exclude name="WordPress.WP.EnqueuedResourceParameters.MissingVersion"/>
        <!-- Any kind of formatting for hook names is fine -->
        <exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores"/>
        <!-- I don't think in Yoda speak. See https://github.com/humanmade/WordPress-Importer/blob/7fa0a24c12818e60f70d73293b79a277e742b2f1/phpcs.ruleset.xml#L25-L44 -->
        <exclude name="WordPress.PHP.YodaConditions" />
    </rule>
</ruleset>

I'd expect the following behaviour

Instead this happened

Referenced sniff "PHPCompatibility.PHP.RemovedExtensions" does not exist

Environment

Tested Against develop branch?

kingkool68 commented 4 months ago

Sorry I'm a dummy and there was an additional phpcs.xml.dist that was conflicting.