phpcs:引用的嗅探“ WordPress”不存在

时间:2020-03-12 05:03:29

标签: phpcs

我已按照this answer的要求安装了phpcs,并将以下内容添加到了我的可视代码settings.json中:

{
    "phpcs.enable": true,
    "phpcs.composerJsonPath": "wp-content/themes/wprig/composer.json",
    "phpcs.standard": "WordPress",
    "phpcs.executablePath": "/Users/Chris/.composer/vendor/bin/phpcs",
}

但是,当我以WordPress主题编辑PHP文件时,Visual Code在右下角显示错误:

phpcs: Referenced sniff "WordPress" does not exist

如果我运行phpcs -i,我会收到:The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1 and PSR12

请问如何为phpcs安装WordPress编码标准?

更新:我按照@ this tutorial的步骤进行了操作,

./vendor/bin/phpcs --config-set installed_paths /Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs

(此后,我会收到肯定的确认)。并且我在VS Code的"phpcs.standard": "WordPress",中添加了settings.json,但是即使重新启动VS Code之后,错误仍然存​​在。

我有WordPress编码标准目录@ /Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs

帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

好像您已经克隆了wpcs @ WordPress项目。 尝试将wpcs克隆到另一个目录中,例如

git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git /Applications/AMPPS/www/wpcs

并将其路径添加到PHP_CodeSniffer配置

phpcs --config-set installed_paths /Applications/AMPPS/www/wpcs

别忘了从主题目录中删除/Applications/AMPPS/www/example.local/wp-content/themes/dev/wpcs