infinum/coding-standards-wp

此包已被弃用,不再维护。作者建议使用 infinum/eightshift-coding-standards 包。

Eightshift WordPress 编码标准

安装次数: 17,321

依赖项: 1

建议者: 0

安全: 0

星标: 16

关注者: 7

分支: 2

公开问题: 1

类型:phpcodesniffer-standard


README

image

Latest Stable Version Release Date of the Latest Version

CI checks

Minimum PHP Version Tested on PHP 7.4 to 8.3

License: MIT Total Downloads

Eightshift WordPress 编码标准

此包包含 Eightshift WordPress 编码标准,适用于 PHP_CodeSniffer。本包的目的是在Eightshift的WordPress项目中实现统一代码,并帮助进行代码审查。

安装

Composer

Composer安装简单。只需运行

composer require infinum/eightshift-coding-standards

或将它添加到你的 composer.json

"require-dev": {
  "infinum/eightshift-coding-standards": "^2.0"
}

将配置文件复制并修改到你的项目中(从项目根目录开始)

cp vendor/infinum/eightshift-coding-standards/phpcs.xml.dist.sample phpcs.xml.dist 

然后,运行以下命令以在项目中运行标准检查

vendor/squizlabs/php_codesniffer/bin/phpcs

你也可以通过指定文件或目录来选择性地检查。

建议

建议安装一个Composer插件来处理PHP_CodeSniffer的标准注册。

在IDE中工作

Sublime Text 3

为了使嗅探器在Sublime Text 3中工作,你需要设置sublime linter,并添加 phpcs linter

然后在你的设置中,需要引用编码标准的路径。它应该看起来像这样

"paths": {
    "linux": [],
    "osx": [
        "${project}/vendor/bin/",
        "/Users/user_name/wpcs/vendor/bin"
    ],
    "windows": []
},

路径取决于你安装标准的位置。然后在linters用户设置中,你需要添加到 linters

"phpcs": {
    "@disable": false,
    "args": [],
    "excludes": [],
    "standard": "Eightshift"
},

或者将 standard 设置为指向根文件夹中的 phpcs.xml.dist(推荐方法

"phpcs": {
    "@disable": false,
    "args": [],
    "excludes": [],
    "standard": "$folder/phpcs.xml.dist"
},

关于全局安装的说明

在你的 wpcs 文件夹中,当添加Eightshift文件夹时,你可以将此仓库克隆到那里,确保注释掉 <config name="installed_paths" value="vendor/wp-coding-standards/wpcs"/> 部分,这样你的嗅探器就不会去查找那个文件夹。

Visual Studio Code

要在VSCode中设置phpcs,请使用 vscode-phpcs 扩展。安装后,在用户设置中设置

"phpcs.enable": true,
"phpcs.standard": "Eightshift",

这将查找项目文件夹中的Eightshift WordPress编码标准,并在每次保存时运行嗅探器。你可以在底部的“问题”选项卡中查看问题。

Atom

要在Atom编辑器中设置phpcs,你需要安装几个包。首先安装Atom的基础linter包:linter。完成后,你将提示安装其依赖项 linter-ui-default。之后,安装 linter-phpcs

linter-phpcs 包的设置中,您可以设置之前安装的 phpcs 的路径,或者允许该包在您的项目中搜索 phpcs 可执行文件。此外,您必须设置标准名称:"Eightshift" 或 Eightshift 的 WordPress 编码标准的 ruleset.xml 路径。我们建议您禁用搜索配置文件,因为这可能会导致使用其他标准。

在 config.cson 中,linter-phpcs 的设置可能如下所示

# If you want to use phpcs executable available in project
"linter-phpcs":
  autoConfigSearch: false
  codeStandardOrConfigFile: "Eightshift"
  disableWhenNoConfigFile: true

# If you want to use specific phpcs executable
"linter-phpcs":
  autoConfigSearch: false
  autoExecutableSearch: false
  codeStandardOrConfigFile: "Eightshift"
  disableWhenNoConfigFile: true
  executablePath: "/Users/user_name/wpcs/vendor/bin/phpcs" #For Mac users
  executablePath: "path_to_composer/vendor/bin/phpcs.bat" # For Windows users

# If you want to use specific standard
"linter-phpcs":
  autoConfigSearch: false
  codeStandardOrConfigFile: "vendor/infinum/eightshift-coding-standards/Eightshift/ruleset.xml"
  disableWhenNoConfigFile: true

致谢

Eightshift WordPress 编码标准由 Infinum 维护并赞助。

许可

Eightshift WordPress 编码标准版权所有 © 2023 Infinum。这是一个免费软件,可以根据 LICENSE 文件中指定的条款重新分发。