Skip to content

Commit bba3cc3

Browse files
committed
Add machine-readable CLI output formats for analyze and fix
1 parent 775146a commit bba3cc3

6 files changed

Lines changed: 432 additions & 49 deletions

File tree

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- **Linked editing ranges.** Place the cursor on a variable and all occurrences within its definition region (from one assignment to the next) enter linked editing mode. Typing a new name updates every occurrence simultaneously without affecting reassigned uses of the same variable name. Ranges exclude the leading `$` sigil so that typing before a variable (e.g. wrapping it in a function call) does not propagate to other occurrences.
1313
- **Invalid class-like kind diagnostics.** Flags class-like names used in positions where their kind is guaranteed to fail at runtime: `new` on abstract classes, interfaces, traits, or enums; `extends` on a final class, interface, or trait; `implements` with a non-interface; trait `use` with a non-trait; `instanceof` with a trait (always false); `catch` with a non-Throwable type or trait; and traits in native type-hint positions. Severity follows PHP semantics: unconditional fatal errors are Error, runtime-conditional failures are Warning.
1414
- **Nested array shape inference from multi-level key assignments.** Assignments like `$b['a']['b'] = 'x'` now produce a nested array shape type (`array{a: array{b: string}}`), enabling array key completion and hover for arrays built incrementally with nested keys. Previously only single-level key assignments were tracked.
15+
- **Machine-readable CLI output.** Both `analyze` and `fix` accept a `--format` flag with three options: `table` (default, the existing human-readable output), `github` (GitHub Actions workflow commands that appear as inline annotations on pull request diffs), and `json` (structured output for dashboards and tooling). When no format is specified and the `GITHUB_ACTIONS` environment variable is set, table output automatically includes GitHub annotations alongside the human-readable table, matching PHPStan's behaviour.
1516

1617
### Fixed
1718

docs/todo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ within the same impact tier.
2626
| # | Item | Impact | Effort |
2727
| --- | ---------------------------------------------------------------------------------------------------------------------------- | ----------- | ------ |
2828
| A36 | [Import all missing classes](todo/actions.md#a36-import-all-missing-classes) (bulk import) | Medium | Low |
29-
| F6 | [Machine-readable CLI output formats](todo/lsp-features.md#f6-machine-readable-cli-output-formats) (`--format github\|json`) | Medium | Low |
3029
| D4 | [Unused variable diagnostic](todo/diagnostics.md#d4-unused-variable-diagnostic) | Medium | Medium |
3130
| D12 | [Mago linter integration](todo/diagnostics.md#d12-mago-linter-integration-optional-diagnostics) | Medium | Medium |
3231
| F4 | [Return type and closure parameter type inlay hints](todo/lsp-features.md#f4-return-type-and-closure-parameter-type-inlay-hints) | Medium | Medium |

docs/todo/lsp-features.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -240,35 +240,6 @@ index (X4), the lookup becomes a simple index query.
240240
Consider implementing after X4 (full background indexing) ships, or
241241
accept the same scan-based latency that Find References currently has.
242242

243-
## F6. Machine-readable CLI output formats
244-
245-
**Impact: Medium · Effort: Low**
246-
247-
Add a `--format` flag to `analyze` and `fix` that controls the output
248-
format. The default remains the current human-readable table.
249-
250-
### Formats
251-
252-
- **`github`** — Emit
253-
[workflow commands](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message)
254-
(`::warning file=...::message`) so diagnostics appear as inline
255-
annotations on pull request diffs. This is the highest-priority
256-
format because GitHub Actions is the most common CI environment for
257-
PHP projects.
258-
- **`json`** — One JSON object per diagnostic (or a top-level array).
259-
Enables integration with custom dashboards, editor plugins, and
260-
other tooling that wants to consume PHPantom output programmatically.
261-
262-
### Implementation
263-
264-
The output logic in `analyse.rs` and `fix.rs` currently writes
265-
directly to stderr/stdout with ANSI formatting. Extract the rendering
266-
behind a trait or enum so each format can be selected at the call
267-
site. The `--no-colour` flag becomes redundant for non-table formats
268-
but should continue to work for the default table output.
269-
270-
---
271-
272243
## F7. Evaluatable expression support (DAP integration)
273244

274245
**Impact: Low-Medium · Effort: Low**

0 commit comments

Comments
 (0)