think-zap/coding-standards

Zap 编码标准(PHPCS)

安装: 17

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 0

类型:phpcodesniffer-standard

2.0.0 2024-09-02 14:17 UTC

This package is auto-updated.

Last update: 2024-09-24 09:09:23 UTC


README

Zap 编码标准是一组主要用于与 Zap 竞赛插件配合使用的 PHP_CodeSniffer 规则。

要求

  • PHP ^8.2

安装

Composer v2

composer require --dev Think-Zap/coding-standards "^2.0"`

Composer v1

添加到 repositories 对象

    {
      "type": "vcs",
      "url": "git@github.com:Think-Zap/coding-standards.git"
    }

require-dev

  "Think-Zap/coding-standards": "^3.0"

项目规则集

请确保您本地正在运行 PHP 8.2!

要使用此规则集,请在项目的根目录下创建一个 phpcs.xml.dist 文件,并添加以下内容

<?xml version="1.0"?>
<ruleset>
	<arg name="basepath" value="." />
	<arg name="extensions" value="php" />
	<arg name="severity" value="4" />
	<arg name="tab-width" value="4" />
	<arg name="parallel" value="80" />
	<arg name="colors" />

	<!--  Update to the PHP version your production/local docker container runs on -->
	<config name="testVersion" value="7.4" />
	<!-- php -r 'echo PHP_VERSION_ID;' -->
	<config name="php_version" value="70400" />

	<!-- Fix WordPress's terrible typing breaking PHPCS -->
	<config name="minimum_supported_wp_version" value="5.6.0" />

	<!-- Ignore warnings, show progress of the run and show sniff names -->
	<arg value="nps" />

	<!-- Directories to be checked -->
	<file>./wp-content/plugins</file>

	<!-- Exclude files -->
	<exclude-pattern>*-config.php</exclude-pattern>
	<exclude-pattern>*vendor/</exclude-pattern>
	<exclude-pattern>*tests/*</exclude-pattern>
	<exclude-pattern>*.twig</exclude-pattern>
	<exclude-pattern>*webpack/</exclude-pattern>

	<!-- Include the Zap coding standard -->
	<rule ref="Zap" />
</ruleset>

phpcs.xml 添加到您的 .gitignore

手动使用

PHPCS

./vendor/bin/phpcs --standard=Zap /path/to/files/**.php

PHPCBF

./vendor/bin/phpcbf --standard=Zap /path/to/files/**.php