tengattack/phplint

A configurable linter tool for PHP.

v0.2.5 2021-07-29 17:24 UTC

This package is auto-updated.

Last update: 2024-04-11 10:14:42 UTC


README

A configurable linter tool for PHP.

Introduction

Dependencies

Installation

$ 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

Run

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

Configuration

If no configuration file is specified, it will first read the file .phplint.yml on current working directory as configuration, and if still not exists it will use the default configuration.

You can configure it as you want base on this file: .phplint.yml.

Example

A php file test.php with following content:

<?php

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

}
$ phplint test.php

Output:

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        |
+-----+----------+---------------------------------+-----------------+

Testing

vendor/bin/phpunit

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

License

MIT