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

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

Closed
brothman01 opened this issue Feb 28, 2024 · 5 comments

Comments

@brothman01
Copy link

brothman01 commented Feb 28, 2024

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?

  • [√ ] I have verified the issue still exists in the develop branch of WordPressCS. [that is the branch I am using]
@jrfnl
Copy link
Member

jrfnl commented Feb 28, 2024

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

brothman01 commented Feb 28, 2024

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

@jrfnl ^ (I did not tag you)

@jrfnl
Copy link
Member

jrfnl commented Feb 28, 2024

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

brothman01 commented Feb 28, 2024

@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

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