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: ERROR: Referenced sniff "PHPCSUtils" does not exist #2396

Closed
1 task
theMikeD opened this issue Sep 28, 2023 · 4 comments
Closed
1 task

phpcs: ERROR: Referenced sniff "PHPCSUtils" does not exist #2396

theMikeD opened this issue Sep 28, 2023 · 4 comments

Comments

@theMikeD
Copy link

Bug Description

I have installed the standards per the instructions using composer. I have then set phpStorm to use the project-specific phpcs et al, and the standards installed via composer all appear fine.

However my phpStorm log is filled with phpcs: ERROR: Referenced sniff "PHPCSUtils" does not exist

Minimal Code Snippet

	"require-dev": {
		"wp-coding-standards/wpcs": "^3",
		"sirbrillig/phpcs-variable-analysis": "^2.8",
		"brain/monkey": "2.*",
		"phpunit/php-code-coverage": "^9.2",
		"phpunit/phpunit": "^9",
		"wp-phpunit/wp-phpunit": "^5",
		"yoast/phpunit-polyfills": "^1.0",
		"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
	}

The issue happens when phpStorm attempts to scan a php file.

Environment

Question Answer
PHP version 8.1.22
PHP_CodeSniffer version 3.7.2
WordPressCS version 3.0.1
PHPCSUtils version 1.0.8
PHPCSExtra version 1.1.2
WordPressCS install type Composer project local
IDE (if relevant) PhpStorm 2023.2.2

I see the phpcsstandards folder in vendor
The vendor folder is in a non-standard location, set by

	"config": {
		"vendor-dir": "client-mu-plugins/vendor",
		"allow-plugins": {
			"composer/installers": true,
			"dealerdirect/phpcodesniffer-composer-installer": true,
			"php-http/discovery": true
		}
	},

Additional Context (optional)

I do not get the same warning running on the command line using

 phpcs -ps functions.php --standard=WordPress-Extra

Tested Against develop Branch?

  • I have verified the issue still exists in the develop branch of WordPressCS.

Don't know how to do this.

@jrfnl
Copy link
Member

jrfnl commented Sep 28, 2023

If everything works fine on the command line, this is not a WPCS issue, but a PHPStorm issue. I suggest you ask in a PHPStorm forum for support, though based on your description it sounds like PHPStorm is using a different PHPCS version than the one you installed in the project, which would explain the problem.

Suggest: close as asked in the wrong repo.

P.S.: you should be able to remove the "dealerdirect/phpcodesniffer-composer-installer": "^1.0" requirement as that is now a dependency of WPCS, so to prevent conflicts in the future, you could just let WPCS (or rather PHPCSUtils) handle the supported versions.

@theMikeD
Copy link
Author

As is usual in my life, the act of describing the issue has revealed the solution.

In my case, i had specified a folder in Preferences --> PHP --> Quality Tools, Installed Standards path. I had that set to vendor/wp-coding-standard/wpcs and as soon as I cleared it and restarted, everything started working again. The lightbulb went off after reading the first FAq answer on this page and realizing that the standard would not have to be set manually any more.

At least there is a record for this in case someone else has the same issue.

@jrfnl
Copy link
Member

jrfnl commented Sep 28, 2023

@theMikeD Ah, yes, that very much explains it. Happy to hear that the PHPCSUtils FAQ helped you solve this.

@diegovogel
Copy link

At least there is a record for this in case someone else has the same issue.

THANK YOU @theMikeD. This was driving me mad.

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

3 participants