wunderio / code-quality
GrumPHP 的代码质量检查包装器
Requires
- dealerdirect/phpcodesniffer-composer-installer: *
- drupal/coder: ^8
- mglaman/phpstan-drupal: ^1.1
- pheromone/phpcs-security-audit: ^2.0
- phpcompatibility/php-compatibility: ^9.3
- phpro/grumphp: ^2.5
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- squizlabs/php_codesniffer: ^3.4
- symfony/polyfill-iconv: ^1
- webflo/drupal-finder: ^1.3
Requires (Dev)
- phpunit/phpunit: ^8.3
- dev-main
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.4.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.0
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-sonar-scanner
- dev-feature/108-Integrate-vscode-and-PhpStorm
- dev-hotfix/106-Change-yaml-and-json-task-default-paths
- dev-feature/72-Re-add-code-complexity
- dev-hotfix/99-fix-php_stan-error-with-DrupalAutoloader
- dev-hotfix/#99-fix-php_stan-error-with-DrupalAutoloader
- dev-feature/72-Re-add-ecs-and-code-complexity-for-D10
- dev-feature/93-add-phpstan-extension-installer
- dev-feature/#91-finder-version
- dev-feature/91-finder-version
- dev-fix-autoloader
- dev-feature/#86-Adjust-coding-standards-so-that-it-would-be-possible-to-run-phpcs-with-Lando-PhpStorm
- dev-feature/#84-add-eslint-task
- dev-feature/84-add-eslint-task
- dev-feature/#78-Add-info-to-readme-how-to-run-task-specific-tasks
- dev-feature/#79-Change-the-default-PHP-code-checker-version-to-8.0
- dev-feature/#79-Change-the-default-PHP-code-checker-version-to-8.1
- dev-feature/62-add-psalm-task
- dev-feature/69-Use-local-phpstan.neon
- dev-feature/68-Update-PHPStan
- dev-feature/67-Update-ECS-to-latest-possible-version
- dev-feature/#59-support-drupal-8-and-composer-2
- dev-feature/grumphp-upgrade
- dev-feature/#41-legacy-support
This package is auto-updated.
Last update: 2024-09-12 12:22:17 UTC
README
此 composer 包将使用 https://github.com/phpro/grumphp 在提交代码之前提供一些基本的代码质量检查。
它仅检查 git 提交中修改的文件或新文件,但可以通过运行 vendor/bin/grumphp run
在所有配置的路径上执行检查。
此工具仅扩展 GrumPHP。请阅读其文档了解如何配置工具本身。
执行检查
此存储库目前有以下检查
- Shell 脚本执行位 - check_file_permissions
- PHP Drupal CS 和 PHP 代码安全 - phpcs
- PHP 8.1 兼容性 - php_compatibility
- PHP 语法 - php_check_syntax
- 认知复杂度和其他 ecs sniffs - ecs
- Yaml 语法 - yaml_lint
- Json 语法 - json_lint
- 弃用测试 - php_stan
先决条件
- Composer
- PHP >= 8.1
安装
这只需要在创建项目或启用现有项目的代码检查时进行一次。
composer require wunderio/code-quality --dev
cp vendor/wunderio/code-quality/config/grumphp.yml ./grumphp.yml
cp vendor/wunderio/code-quality/config/phpstan.neon ./phpstan.neon
cp vendor/wunderio/code-quality/config/psalm.xml ./psalm.xml
GrumPHP 的提交钩子将在 composer require 时自动安装。
自定义
配置
配置的详细信息分为以下部分。
任务参数
如果您需要自定义 PHP CodeSniffer 的规则,请将 phpcs.xml 放入与 composer.json 相同的文件夹中,并配置 grumphp.yml
parameters: tasks: phpcs: standard: - phpcs.xml
同样适用于使用其他配置文件(easy-coding-standards)的任何任务。
每个代码质量工具都允许您定义至少 3 件事
run_on
- 将进行检查的多条路径,待处理的文件必须来自相同的路径ignore_patterns
- 将排除文件检查的路径部分extensions
- 应该检查的文件的文件扩展名
有关其他可配置选项的更多信息,请参阅各个任务的文档。
命令
由于 GrumPHP 只是一个 CLI 工具,因此可以触发以下命令
使用方法
在执行 git commit
命令时,pre-commit 挂钩将自动运行。
可以通过 git commit --no-verify
或 git commit -n
来跳过代码扫描,但这种情况仅适用于极少数情况。
您可以通过以下命令手动运行检查:./vendor/bin/grumphp run
要从 grumphp.yml 中定义的任务中运行特定任务,您可以使用 --tasks
参数进行定义。示例
./vendor/bin/grumphp run --tasks=phpcs
在持续集成中的使用
您可以通过在 CI(CircleCi/Jenkins/GitLab CI)中添加以下行来轻松使用代码质量检查器:
./vendor/bin/grumphp run --no-ansi --no-interaction