网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

PHP CodeSniffer通过Composer的WordPress

GG网络技术分享 2025-03-18 16:12 2


问题描述:

Is there a way to install PHPCodeSniffer and WordPress Coding Standards for PHP_CodeSniffer per project via Composer?

I\'ve installed both as dev dependencies and set the installed path to WordPress Coding Standards in CodeSniffer.conf.

Unfortunately phpcs can not resolve to the config file when I run the command in the terminal because it is looking in \"vendor\" folder for \"vendor/squizlabs/php_codesniffer/CodeSniffer.conf\"

Here is my project setup:

composer.json

{

\"require-dev\": {

\"squizlabs/php_codesniffer\": \"^3.2\",

\"wp-coding-standards/wpcs\": \"^0.14.0\"

}

}

CodeSniffer.conf

<?php

$phpCodeSnifferConfig = array (

\'installed_paths\' => \'vendor/wp-coding-standards/wpcs\',

)

?>

Terminal

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

\"ERROR: the \"WordPress\" coding standard is not installed. The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz and PSR1\"

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

有没有办法安装 PHPCodeSniffer PHP_CodeSniffer的WordPress编码标准< / a>每个项目通过 Composer

我已同时安装了dev依赖项并设置了WordPress编码的安装路径 CodeSniffer.conf中的标准。

很遗憾,当我在终端中运行命令时,phpcs无法解析为配置文件,因为它在“vendor”文件夹中查找“vendor / squizlabs / php_codesniffer / CodeSniffer.conf”</ p> \\ n

这是我的项目设置:</ p>

composer.json </ p>

  {

“require-dev”:{

“squizlabs / php_codesniffer”:“^ 3.2”,

“wp-coding-standards / wpcs”:“^ 0.14.0”

}

}

</ code> </ pre>

\\ ñ

CodeSniffer.conf </ p>

 <共 de>&lt;?php 

$ phpCodeSnifferConfig = array(

\'installed_pa​​ths\'=&gt; \'vendor / wp-coding-standards / wpcs\',

?&gt;

</ code> </ pre>

终端</ p>

 <  code> vendor / bin / phpcs -p THEME_NAME --standard = WordPress 

</ code> </ pre>

“错误:未安装”WordPress“编码标准。安装的编码标准是 PEAR,Zend,PSR2,MySource,Squiz和PSR1“</ p>

</ div>

网友观点:

First, you don\'t need to require PHP CodeSniffer explicitly, because wp-coding-standards/wpcs pulls it automatically.

composer.json

{

\\\"require-dev\\\": {

\\\"wp-coding-standards/wpcs\\\": \\\"^0.14.0\\\"

}

}

is sufficient.

To make CodeSniffer aware of the added coding standard, type on the console terminal:

$ vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs

It will automatically create (and later find) the vendor/squizlabs/php_codesniffer/CodeSniffer.conf file.

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

Now, check the installed standards:

$ 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

标签:

提交需求或反馈

Demand feedback