gpt4 book ai didi

PHP CodeSniffer WordPress 通过 Composer

转载 作者:行者123 更新时间:2023-12-04 16:06:24 28 4
gpt4 key购买 nike

有没有办法安装PHPCodeSnifferWordPress Coding Standards for PHP_CodeSniffer每个项目通过 Composer ?
我已经将两者都安装为开发依赖项,并在 CodeSniffer.conf 中设置了 WordPress 编码标准的安装路径。
不幸的是,当我在终端中运行命令时,phpcs 无法解析到配置文件,因为它在“vendor”文件夹中查找“vendor/squizlabs/php_codesniffer/CodeSniffer.conf”

这是我的项目设置:

Composer .json

{
"require-dev": {
"squizlabs/php_codesniffer": "^3.2",
"wp-coding-standards/wpcs": "^0.14.0"
}
}

代码嗅探器配置文件
<?php
$phpCodeSnifferConfig = array (
'installed_paths' => 'vendor/wp-coding-standards/wpcs',
)
?>

终端
vendor/bin/phpcs -p THEME_NAME --standard=WordPress

“错误:未安装“WordPress”编码标准。已安装的编码标准是 PEAR、Zend、PSR2、MySource、Squiz 和 PSR1”

最佳答案

首先,您不需要明确地要求 PHP CodeSniffer,因为 wp-coding-standards/wpcs自动拉动它。
composer.json

{
"require-dev": {
"wp-coding-standards/wpcs": "^0.14.0"
}
}

足够了。

要让 CodeSniffer 知道添加的编码标准,请在控制台终端上键入:
$ vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs

它将自动创建(然后找到) vendor/squizlabs/php_codesniffer/CodeSniffer.conf文件。

This should have happened automagically during the installation; the package contains instructions for that, but for some reason they were not executed.



现在,检查已安装的标准:
$ vendor/bin/phpcs -i
The installed coding standards are MySource, PSR2, Squiz, Zend, PSR1, PEAR, WordPress-Extra, WordPress, WordPress-Core, WordPress-VIP and WordPress-Docs

关于PHP CodeSniffer WordPress 通过 Composer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485778/

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