gpt4 book ai didi

php - VScode PHPCS 扩展错误 : Referenced Sniff "WordPress-Core" does not exist

转载 作者:行者123 更新时间:2023-12-04 10:33:48 25 4
gpt4 key购买 nike

我想将 PHP CodeSniffer 添加到 VScode。

在 VScode 中,我收到错误 'phpcs: Referenced sniff "WordPress-Core" does not exist'
但是,当我在终端中运行以下命令时:phpcs --standard="WordPress-Core" dropdowns.phpPHP CodeSniffer 按预期工作,终端输出如下:

--------------------------------------------------------------------------------
FOUND 34 ERRORS AND 17 WARNINGS AFFECTING 51 LINES
--------------------------------------------------------------------------------
15 | WARNING | [x] Array double arrow not aligned correctly; expected 10
| | space(s) between "'id'" and double arrow, but found 1.
17 | WARNING | [x] Array double arrow not aligned correctly; expected 4
| | space(s) between "'taxonomy'" and double arrow, but found
| | 1.
18 | WARNING | [x] Array double arrow not aligned correctly; expected 5
| | space(s) between "'orderby'" and double arrow, but found
| | 1.
34 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 10 spaces but found 1 space
35 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 7 spaces but found 1 space
36 | ERROR | [x] Short array syntax is not allowed
44 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 2 spaces but found 1 space
84 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 2 spaces but found 1 space

我的 settings.json 文件如下所示:
{
"workbench.colorTheme": "Default Light+",
"window.zoomLevel": 0,
"phpcs.standard": "WordPress",
"phpcs.executablePath": "/Users/michelle/.composer/vendor/bin/phpcs",
"phpcs.enable": true,
"phpcs.showWarnings": true,
"phpcs.showSources": true,
}

我的 phpcs.ruleset.xml 看起来像这样:
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards">
<description>My Project's Coding Standards</description>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Docs"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Extra"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Core"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPressVIPMinimum"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-VIP-Go"/>
</ruleset>

最佳答案

我通过更新此文件中的规则引用解决了此错误:~/.composer/vendor/wp-coding-standards/wpcs/WordPress也是绝对路径。 WordPress 编码标准的最终规则集.xml 现在看起来像这样:

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress" namespace="WordPressCS\WordPress" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">

<description>WordPress Coding Standards</description>

<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Core"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Docs"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Extra">
<!-- Prevent duplicate messages + deprecation notice from deprecated sniff. -->
<exclude name="WordPress.WP.TimezoneChange.timezone_change_date_default_timezone_set"/>
<exclude name="WordPress.WP.TimezoneChange.DeprecatedSniff"/>
</rule>

</ruleset>

关于php - VScode PHPCS 扩展错误 : Referenced Sniff "WordPress-Core" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60284975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com