Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
mackensen opened this issue Mar 19, 2024 · 4 comments
Closed
1 task done

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

mackensen opened this issue Mar 19, 2024 · 4 comments

Comments

@mackensen
Copy link

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?

  • I have verified the issue still exists in the develop branch of WordPressCS.
@jrfnl
Copy link
Member

jrfnl commented Mar 20, 2024

  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
Copy link
Author

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

@mackensen
Copy link
Author

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
Copy link
Member

jrfnl commented Mar 20, 2024

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:

  • When no --standard=... is passed on the command-line, PHPCS will look for a [.]phpcs.xml[.dist] file and use that as the ruleset/standard. When such a file is not found, it will fall-back to the default standard.
  • When passing --standard=... on the command-line, PHPCS will not even look any further, it will use whatever standard is provided. I.e. command-line args will always overrule everything.
    Keep in mind, you can pass multiple standards as a comma-separated list and they don't all have to be named ones either: --standard=WordPress,myphpcs.xml.
    It will be rare to need this though and you'd be better off documenting the rules which apply to your project in a project specific [.]phpcs.xml[.dist] file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants