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

ERROR: Referenced sniff "PHPCompatibilityWP" does not exist #166

Open
DylandeBruijn opened this issue Feb 11, 2025 · 6 comments
Open

ERROR: Referenced sniff "PHPCompatibilityWP" does not exist #166

DylandeBruijn opened this issue Feb 11, 2025 · 6 comments

Comments

@DylandeBruijn
Copy link

Hi,

I don't know if this is a specific PHP Codesniffer issue or a problem with the theme but I get the following error:

ERROR: Referenced sniff "PHPCompatibilityWP" does not exist

Do I need to install the sniff globally?

I hope you can point me in the right direction.

@gregsullivan
Copy link
Owner

Hi Dylan—Thanks for posting this!

Can you please confirm that you've run composer install? The PHPCompatibilityWP sniff should be installed by this line in composer.json:

"phpcompatibility/phpcompatibility-wp": "^2.1",

Happy to test more, though, and figure out why it's not working on your side!

@DylandeBruijn
Copy link
Author

Hi Greg, thank you for your quick reply. This error occurs in the PHP_CodeSniffer output tab in Vscode.

Image

This is my composer.json

{
	"require-dev": {
		"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
		"phpcompatibility/phpcompatibility-wp": "^2.1",
		"sirbrillig/phpcs-changed": "^2.11",
		"sirbrillig/phpcs-variable-analysis": "^2.11",
		"wp-cli/i18n-command": "^2.6",
		"wp-coding-standards/wpcs": "^3.1"
	},
	"scripts": {
		"php:lint": "vendor/bin/phpcs -p -s",
		"php:lint:errors": "vendor/bin/phpcs -p -s --runtime-set ignore_warnings_on_exit 1",
		"php:lint:autofix": "vendor/bin/phpcbf",
		"php:lint:changed": "vendor/bin/phpcs-changed --git --git-unstaged",
		"make-pot": "wp i18n make-pot . theme/languages/pleiades.pot"
	},
	"config": {
		"allow-plugins": {
			"dealerdirect/phpcodesniffer-composer-installer": true
		}
	}
}

I have this set in my Vscode settings.json

  "[php]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "obliviousharmony.vscode-php-codesniffer"
  }

@DylandeBruijn
Copy link
Author

DylandeBruijn commented Feb 12, 2025

I also ran vendor/bin/phpcs -i and this is the following output:

The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, Modernize, NormalizedArrays, Universal, PHPCSUtils, VariableAnalysis, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra

I'm confused why phpcs can't find the sniff but PHPCompatibilityWP is installed.

@gregsullivan
Copy link
Owner

I remember needing to debug this at some point myself. I believe the issue is with VS Code's choice of PHP_CodeSniffer executable.

One thing you can do to debug is run composer run php:lint and see whether that works. If it does, that would confirm the issue is with your IDE, not with your repository.

In case this helps, these are my other settings in VS Code:

"phpCodeSniffer.standard": "Custom",
"phpCodeSniffer.standardCustom": "phpcs.xml.dist",
"phpCodeSniffer.lintAction": "Save",
"phpCodeSniffer.autoExecutable": true,
"phpCodeSniffer.executable": "",

I don't use VS Code as my primary IDE anymore, so these may be outdated or otherwise inappropriate, just to warn you.

@DylandeBruijn
Copy link
Author

Hi Greg,

I tried the settings you provided and got some new errors so I need to do some more tinkering. Thanks for helping out with this issue so far!

@gregsullivan
Copy link
Owner

You're very welcome! If you're able to sort this out, I'd love to hear how you resolved the issue on your side.

In case you're able to confirm: Is composer run php:lint working without issue for you?

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