WordPress / WordPress-Coding-Standards

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

phpcs: The "WordPress" coding standard is not installed. Please review your configuration an try again. #2427

Closed brothman01 closed 6 months ago

brothman01 commented 6 months ago

I have been using phpcs with wpcs for a while so I am confused here.

Bug Description

What did you expect to happen? What actually happened? I expected it to lint the file. -->

Minimal Code Snippet

When I execute phpcs index.php --standard="WordPress" in a terminal I get the error "ERROR: Referenced sniff "PHPCSUtils" does not exist".

When I execute phpcs -i in a terminal I can see that WordPress is in the installed list. "The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra"

The code in the file

The code in the php file does not matter because the command cannot be executed.

The PSR2 standard does work, so I do not think the problem is not with the phpcs installation. -->

Environment

Question Answer
PHP version 8.2.12
WordPressCS install type Composer global
IDE (if relevant) VSCode 1.87.0

Tested Against develop Branch?

jrfnl commented 6 months ago

@brothman01 How did you install WordPressCS ? Looks like you didn't answer that question or is "Composer global" your answer ?

If so, there must be a version mismatch as the list of installed standards from phpcs -i does not match what I'd expect to see when someone is running with WordPressCS develop as you claim to be.

Can you please run composer global info and post the output ?

brothman01 commented 6 months ago

yes composer global was my answer. I edited the comment to remove the eg but it is not showing on the comment. I ran the command but I think the output is weird:

composer global info


Changed current directory to /Users/bmr/.composer
squizlabs/php_codesniffer 3.7.2 PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violati...```
brothman01 commented 6 months ago

@jrfnl ^ (I did not tag you)

jrfnl commented 6 months ago

@brothman01 Well, if that is what the response is, then you don't have WPCS installed via Composer global and I'm not surprised it doesn't work.

I suggest you follow the installation instructions in the README to install it and try again.

brothman01 commented 6 months ago

@jrfnl I can use WPCS and have been using it so it is installed. When I execute phpcs index.php --standard="WordPress" (specifying the WordPress ruleset) it outputs errors so something is installed.

Solution: I took your advice and took a look at the installation instructions.. I ran composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true and composer global require --dev wp-coding-standards/wpcs:"^3.0" so it looks to me like I was either missing that dealerdirect plugin OR running an old version of wpcs so it all works as expected now.

Thanks