infinum / coding-standards-wp
Requires
- php: >=7.4
- phpcompatibility/phpcompatibility-wp: ^2.1.4
- slevomat/coding-standard: ^8.13.0
- wp-coding-standards/wpcs: dev-hotifx/escape-output-sniff
Requires (Dev)
- php-parallel-lint/php-console-highlighter: ^1.0.0
- php-parallel-lint/php-parallel-lint: ^1.3.2
- phpcsstandards/phpcsdevtools: ^1.2.0
- phpunit/phpunit: ^7.0
- roave/security-advisories: dev-master
- dev-main
- 3.0.0
- 2.0.0-beta
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1
- 1.0.1
- 1.0.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/2.1.0
- dev-php8-update
- dev-update-devtools-xml-sniff
- dev-fix-edgecase-security-sniff
- dev-php-8.2-update
This package is auto-updated.
Last update: 2024-05-20 07:32:08 UTC
README
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 文件中指定的条款重新分发。