WordPress / WordPress-Coding-Standards

PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions
MIT License
2.53k stars 471 forks source link

Exclude patterns in .phpcs.xml.dist not honored #2433

Closed mackensen closed 5 months ago

mackensen commented 5 months ago

Bug Description

I'm upgrading an older plugin project to use the current versions of this library:

    "require-dev": {
        "wp-coding-standards/wpcs": "^3.0",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0"
    },

I'm running vendor/bin/phpcs -ps . --standard=WordPress from the root of my plugin folder. The command runs out of memory because it traverses node_modules. I'm using the sample phpcs.xml.dist.sample with the standard exclusions that should prevent this behavior:

    <!-- Exclude the Composer Vendor directory. -->
    <exclude-pattern>/vendor/*</exclude-pattern>

    <!-- Exclude the Node Modules directory. -->
    <exclude-pattern>/node_modules/*</exclude-pattern>

If I run the command specifying the exclusions it runs as expected without the memory error: vendor/bin/phpcs -ps . --standard=WordPress --ignore=vendor,node_modules.

Environment

Question Answer
PHP version 7.4.33
PHP_CodeSniffer version 3.9.0
WordPressCS version 3.0.1
PHPCSUtils version 1.0.10
PHPCSExtra version 1.2.1
WordPressCS install type Composer project local
IDE (if relevant) N/A

Tested Against develop Branch?

jrfnl commented 5 months ago
  1. This is not something which WPCS can do anything about, WPCS doesn't do the filtering. You'd be better off reporting this to the PHP_CodeSniffer project.
  2. Not sure what versions you are upgrading from, as those were not mentioned, but the filter behaviour in PHPCS itself hasn't undergone any changes in the last few years, so I don't understand how this is related to your upgrade to WPCS 3.0.
mackensen commented 5 months ago

I'm upgrading from 2.1, and I'll follow up with that project. Thanks!

mackensen commented 5 months ago

I think the specific issue is that I didn't realize/remember that specifying the standard (--standard=WordPress) means any custom ruleset you define is ignored.

jrfnl commented 5 months ago

I think the specific issue is that I didn't realize/remember that specifying the standard (--standard=WordPress) means any custom ruleset you define is ignored.

@mackensen Ah, I missed that you were running with --standard=WordPress in the original command... In which case, yes, 100% correct.

And for anyone else trying to understand this: