|
| 1 | +# Mago Linter |
| 2 | + |
| 3 | +Run linting rules on PHP code to identify style violations, code smells, and potential bugs. |
| 4 | + |
| 5 | +## Composer |
| 6 | + |
| 7 | +```bash |
| 8 | +composer require --dev carthage-software/mago |
| 9 | +``` |
| 10 | + |
| 11 | +## Behavior |
| 12 | + |
| 13 | +The task always runs in `--fix --dry-run` mode: it previews what automatic fixes would be applied without modifying any files, and fails if issues are found. When running in a `git pre-commit` context, only staged files are linted (`--staged`). In a `run` context, all files are linted. |
| 14 | + |
| 15 | +If the task fails, GrumPHP will offer to re-run with `--fix` applied. The fix mode can be configured via `fix-mode`. |
| 16 | + |
| 17 | +## Config |
| 18 | + |
| 19 | +The task lives under the `mago_lint` namespace and has following configurable parameters: |
| 20 | + |
| 21 | +```yaml |
| 22 | +# grumphp.yml |
| 23 | +grumphp: |
| 24 | + tasks: |
| 25 | + mago_lint: |
| 26 | + semantics: ~ |
| 27 | + pedantic: ~ |
| 28 | + only: [] |
| 29 | + retain-codes: [] |
| 30 | + ignore-baseline: ~ |
| 31 | + sort: ~ |
| 32 | + fix-mode: safe |
| 33 | + minimum-report-level: ~ |
| 34 | +``` |
| 35 | +
|
| 36 | +**semantics** |
| 37 | +
|
| 38 | +*Type: bool* |
| 39 | +
|
| 40 | +Skip linter rules and only perform basic syntax and semantic validation. Checks that your PHP code parses correctly and has valid semantic structure, without applying any style or quality rules. Useful for quick syntax validation. |
| 41 | +
|
| 42 | +**pedantic** |
| 43 | +
|
| 44 | +*Type: bool* |
| 45 | +
|
| 46 | +Enable every available linter rule for maximum thoroughness. Overrides your configuration and enables all rules, including those disabled by default. The output will be extremely verbose and is not recommended for regular use. Useful for comprehensive code audits. |
| 47 | +
|
| 48 | +**only** |
| 49 | +
|
| 50 | +*Type: string[] — Default: []* |
| 51 | +
|
| 52 | +Run only the specified rules, ignoring the configuration file. Provide a list of rule codes (e.g. `invalid-argument`, `semantics`). Overrides your `mago.toml` configuration and is useful for targeted analysis. |
| 53 | + |
| 54 | +**retain-codes** |
| 55 | + |
| 56 | +*Type: string[] — Default: []* |
| 57 | + |
| 58 | +Reporting filter: only display issues matching the specified rule codes (e.g. `invalid-argument`, `semantics`). All rules still run; only the output is filtered. Can be specified multiple times. |
| 59 | + |
| 60 | +Note: this differs from `only`, which restricts which rules are executed. |
| 61 | + |
| 62 | +**ignore-baseline** |
| 63 | + |
| 64 | +*Type: bool* |
| 65 | + |
| 66 | +Ignore the baseline file and report all issues, including those currently suppressed. The baseline file must be generated manually via `mago lint --generate-baseline`. |
| 67 | + |
| 68 | +**sort** |
| 69 | + |
| 70 | +*Type: bool* |
| 71 | + |
| 72 | +Sort reported issues by severity level, rule code, and file location. By default, issues are reported in the order they appear in files. |
| 73 | + |
| 74 | +**fix-mode** |
| 75 | + |
| 76 | +*Default: safe — Possible values: `safe`, `potentially-unsafe`, `unsafe`* |
| 77 | + |
| 78 | +Controls which fixes are applied when GrumPHP offers to auto-fix: |
| 79 | + |
| 80 | +- `safe` — apply only safe fixes (default) |
| 81 | +- `potentially-unsafe` — also apply fixes that may require manual review |
| 82 | +- `unsafe` — also apply fixes that might change code behavior |
| 83 | + |
| 84 | +**minimum-report-level** |
| 85 | + |
| 86 | +*Default: null (mago default: all levels)* |
| 87 | + |
| 88 | +Minimum severity level to display in the report. Issues below this level are not shown. Possible values: `note`, `help`, `warning`, `error` |
| 89 | + |
0 commit comments