dallask / all-in-one-code-checker
此软件包最新版本(1.0.1)没有可用的许可证信息。
1.0.1
2021-10-11 05:32 UTC
Requires
- dallask/grumphp-prettier-task: ^1.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.1
- drupal/coder: ^8.3
- ergebnis/composer-normalize: ^2.15
- php-parallel-lint/php-parallel-lint: ^1.3
- phpmd/phpmd: ^2.10
- phpro/grumphp: ^1.4
- space48/grumphp-stylelint-task: ^1.0
This package is auto-updated.
Last update: 2024-09-11 11:59:14 UTC
README
概述
提供了一套库,可以轻松设置基于 GrumPHP 的代码质量检查,适用于 Drupal 模块/主题/配置文件。有关更多详细信息,请参阅这篇 Lullabot 文章。
注意: 此库旨在帮助托管在单独 Git 仓库中的贡献/自定义 Drupal 模块/主题/配置文件。
安装
-
运行
composer require dallask/all-in-one-code-checker
-
将
grumphp.yml
复制到项目的根目录(不是 Drupal 根目录)与grumphp.yml.dist
一起 -
调整
grumphp.yml
中的配置 -
运行
npm init
(可选) -
运行
npm install dallask-all-in-one-code-checker
-
如果您在 package.json 文件中看不到所需的脚本,只需从文件:./node_modules/dallask-all-in-one-code-checker/package.json 中复制它们即可
"scripts": {
"grumphp": "./vendor/bin/grumphp run",
"phpcs:total": "./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile .",
"phpcs:current": "./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile $(git diff --name-status | grep -v \"^[RD]\" | awk '{ print $2 }')",
"phpcs:total:fix": "./vendor/bin/phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile .",
"phpcs:current:fix": "./vendor/bin/phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile $(git diff --name-status | grep -v \"^[RD]\" | awk '{ print $2 }')",
"stylelint:total": "stylelint '**/*.scss'",
"stylelint:current": "stylelint $(git diff --name-status | grep '\\.scss$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"stylelint:total:fix": "stylelint '**/*.scss' --fix",
"stylelint:current:fix": "stylelint --fix $(git diff --name-status | grep '\\.scss$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"prettier:total": "prettier '**/*' --check",
"prettier:current": "prettier --check $(git diff --name-status | grep '\\.scss$\\|\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"prettier:total:fix": "prettier '**/*' --write",
"prettier:current:fix": "prettier --write $(git diff --name-status | grep '\\.scss$\\|\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"eslint:total": "eslint '**/*.js'",
"eslint:current": "eslint $(git diff --name-status | grep '\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"eslint:total:fix": "eslint '**/*.js' --fix",
"eslint:current:fix": "eslint --fix $(git diff --name-status | grep '\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')"
}
就是这样。现在,所有任务(如下所述)都会在每次 git commit
时运行。
注意: 作为安装的一部分,GrumPHP 会向仓库添加
pre-commit
钩子。在安装/卸载时,现有的pre-commit
可能会被 破坏。
功能
- PHPCS 与 Drupal 标准一致。
- PHP Lint
- YAML Lint
- Composer
- Composer Normalize
- JSONLint
- PHP 复制/粘贴检测器 (CPD)
更多检查/验证器的长列表可在 此处 获取。
NPM 脚本
您可以使用以下脚本来检查和修复您的文件
grumphp - total grumphp check according to your grumphp.yml config
PHPCS:
phpcs:total - total phpcs check for all project files
phpcs:total:fix - total phpcbf fix for all project files
phpcs:current - phpcs check for project files that were changed
phpcs:current:fix - phpcbf fix for project files that were changed
Stylelint:
stylelint:total - stylelint check for all project files
stylelint:total:fix - stylelint fix for all project files
stylelint:current - stylelint check for project files that were changed
stylelint:current:fix - stylelint fix for project files that were changed
Prettier:
prettier:total - prettier check for all project files
prettier:total:fix - prettier fix for all project files
prettier:current - prettier check for project files that were changed
prettier:current:fix - prettier fix for project files that were changed
ESLint:
eslint:total - eslint check for all project files
eslint:total:fix - eslint fix for all project files
eslint:current - eslint check for project files that were changed
eslint:current:fix - prettier fix for project files that were changed
Just run `npm run script_name` in root directory.
Composer 脚本
您可以使用以下 composer 脚本来检查和修复您的文件(只需将它们从 composer.json 文件复制到您的项目 composer.json 中,并根据需要修改选项)
"scripts": {
"post-install-cmd": [
"npm install"
],
"post-update-cmd": [
"npm install"
],
"grumphp": "./vendor/bin/grumphp run",
"phpcs:total": "./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile .",
"phpcs:current": "./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile $(git diff --name-status | grep -v \"^[RD]\" | awk '{ print $2 }')",
"phpcs:total:fix": "./vendor/bin/phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile .",
"phpcs:current:fix": "./vendor/bin/phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile $(git diff --name-status | grep -v \"^[RD]\" | awk '{ print $2 }')",
"stylelint:total": "./node_modules/.bin/stylelint '**/*.scss'",
"stylelint:current": "./node_modules/.bin/stylelint $(git diff --name-status | grep '\\.scss$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"stylelint:total:fix": "./node_modules/.bin/stylelint '**/*.scss' --fix",
"stylelint:current:fix": "./node_modules/.bin/stylelint --fix $(git diff --name-status | grep '\\.scss$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"prettier:total": "./node_modules/.bin/prettier '**/*' --check",
"prettier:current": "./node_modules/.bin/prettier --check $(git diff --name-status | grep '\\.scss$\\|\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"prettier:total:fix": "./node_modules/.bin/prettier '**/*' --write",
"prettier:current:fix": "./node_modules/.bin/prettier --write $(git diff --name-status | grep '\\.scss$\\|\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"eslint:total": "./node_modules/.bin/eslint '**/*.js'",
"eslint:current": "./node_modules/.bin/eslint $(git diff --name-status | grep '\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')",
"eslint:total:fix": "./node_modules/.bin/eslint '**/*.js' --fix",
"eslint:current:fix": "./node_modules/.bin/eslint --fix $(git diff --name-status | grep '\\.js$' | grep -v \"^[RD]\" | awk '{ print $2 }')"
}
grumphp - total grumphp check according to your grumphp.yml config
PHPCS:
phpcs:total - total phpcs check for all project files
phpcs:total:fix - total phpcbf fix for all project files
phpcs:current - phpcs check for project files that were changed
phpcs:current:fix - phpcbf fix for project files that were changed
Stylelint:
stylelint:total - stylelint check for all project files
stylelint:total:fix - stylelint fix for all project files
stylelint:current - stylelint check for project files that were changed
stylelint:current:fix - stylelint fix for project files that were changed
Prettier:
prettier:total - prettier check for all project files
prettier:total:fix - prettier fix for all project files
prettier:current - prettier check for project files that were changed
prettier:current:fix - prettier fix for project files that were changed
ESLint:
eslint:total - eslint check for all project files
eslint:total:fix - eslint fix for all project files
eslint:current - eslint check for project files that were changed
eslint:current:fix - prettier fix for project files that were changed
Just run `composer run-script script_name` in root directory.
用法
- 要从 CLI 开始,请使用
./vendor/bin/grumphp run
。它将仅检查由git add
添加的文件。 - 只需遵循 GrumPHP 文档即可。