pun lint
Find code that could be written better.
Find code that could be written better. Use --fix to apply the fixes.
Usage
pun lint [paths] [options]
pun lint # report problems
pun lint --fix # apply fixes
pun lint -A lint/style # turn a group off for this run
pun lint --max-warnings 10 # fail on more than 10 warnings
Options
| Option | Description |
|---|---|
--fix |
Apply the fixes. Skips rules with fix = "off". |
-A, --allow <rule> |
Turn a rule or group off. |
-W, --warn <rule> |
Turn a rule or group on as a warning. |
-D, --deny <rule> |
Turn a rule or group on as an error. |
--deny-warnings |
Fail on any warning. |
--max-warnings <n> |
Fail on more than n warnings. |
--concise |
One line per problem. |
--format=<fmt> |
Report as json, checkstyle, junit, gitlab, github or agent. |
--no-cache |
Check every file again. |
-q |
Print nothing. The exit code gives the result. |
Lint also takes the file options of pun format, such as --dirty, --staged and --diff.
What happens
- Reads the
[lint]preset, sets and rules frompun.toml. - Checks each file and prints the problems.
- With
--fix, edits the files. It does not format them, so usepun check --fixfor both. - Only
errorrules fail the run.warnrules only report. - Reads standard input (
-or--stdin-filename) only with--fix, and prints the fixed code. Without--fix, standard input is a run error (exit 2): pass the files to check instead. - Skips Blade,
vendor/,bootstrap/cache,build,node_modulesandstorage.
[lint]
preset = "recommended"
[lint.rules]
"style/require-final-class" = "error"
"types/no-loose-comparison" = { level = "warn", fix = "off" }
"style/no-short-ternary" = "off"
To ignore one line, add // @pun-ignore <rule> -- <reason>. See ignore comments.
Limitations
- Pun doesn’t have every Rector and PHP-CS-Fixer rule yet. The rule reference marks the missing ones as Planned.
- A group turns on only the rules Pun has. Naming a Planned rule directly is a config error.
- Rules from PHP-CS-Fixer accept only
@pun-ignore-file, not line or region ignores. - An overriding method gets a return type only when both classes are in
vendor/, or both are outside it.
Exit codes
| Code | Meaning |
|---|---|
| 0 | No errors. |
| 1 | Errors, or too many warnings. |
| 2 | Pun could not run. |