tengattack/phplint

PHP的可配置代码检查工具。

v0.3.0 2024-08-10 15:33 UTC

This package is auto-updated.

Last update: 2024-09-10 15:46:03 UTC


README

PHP的可配置代码检查工具。

介绍

依赖关系

安装

$ composer global require tengattack/phplint
$ # htmllint is used by rule `html` (it has to be latest)
$ npm i -g htmllint/htmllint-cli
$ # stylelint is used by rule `html`
$ npm i -g stylelint
$ # scss-lint is used by rule `html` (deprecated)
$ gem install scss_lint

运行

$ export PATH=$PATH:~/.composer/vendor/bin
$ phplint /path/to/phpfile

配置

如果没有指定配置文件,它将首先读取当前工作目录中的文件 .phplint.yml 作为配置,如果该文件不存在,则使用默认配置。

您可以根据此文件进行配置: .phplint.yml

示例

以下内容的PHP文件 test.php

<?php

$a =false;
$b = $a ?? 1;
if($b) {

}
$ phplint test.php

输出

test.php:
+-----+----------+---------------------------------+-----------------+
| loc | severity | message                         | ruleId          |
+-----+----------+---------------------------------+-----------------+
| 3:5 | error    | Infix operators must be spaced. | space-infix-ops |
| 5:1 | error    | A space is required after 'if'. | keyword-spacing |
| 5:8 | error    | Empty block statement.          | no-empty        |
+-----+----------+---------------------------------+-----------------+

测试

vendor/bin/phpunit

# single rule test
vendor/bin/phpunit tests/rules/curly.php

许可证

MIT