infinum/eightshift-coding-standards

Eightshift WordPress 编码规范

安装次数: 60,194

依赖项: 2

建议者: 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",

这将在你的项目 vendor 文件夹中查找 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文件中指定的条款进行重新分发。