Skip to content

Parse PHPStan JSON in flymake-phpstan, matching flycheck - #69

Merged
zonuexe merged 1 commit into
masterfrom
feature/flymake-json
Jul 17, 2026
Merged

Parse PHPStan JSON in flymake-phpstan, matching flycheck#69
zonuexe merged 1 commit into
masterfrom
feature/flymake-json

Conversation

@zonuexe

@zonuexe zonuexe commented Jul 17, 2026

Copy link
Copy Markdown
Member

Brings flymake-phpstan up to flycheck-phpstan's level by parsing PHPStan's JSON output.

Why

flymake-phpstan asked for the raw format and scraped file:line:message with a regexp, so it showed only the bare message. flycheck-phpstan has read JSON for a while and surfaces much more — identifier, tip, and the metadata that powers phpstan-insert-ignore / phpstan-copy-dumped-type. This closes that gap.

What changes

--error-format=json, parsed with the shared phpstan--parse-json. A Flymake session now:

  • shows each diagnostic's identifier and tip (🪪 / 💡), gated by flymake-phpstan-ignore-metadata-list and joined with flymake-phpstan-metadata-separator — mirrors of the existing flycheck options;
  • refreshes phpstan--ignorable-errors and phpstan--dumped-types in the source buffer, so phpstan-insert-ignore and phpstan-copy-dumped-type work from Flymake, not just Flycheck;
  • locates the JSON by the first line starting with {, so the progress a container writes to STDERR is skipped (same handling as flycheck);
  • surfaces a no-JSON failure — silent for "No files found to analyse." in a modified buffer, a warning otherwise — instead of scraping it into nothing.

Diagnostics are now :error level (were :warning), matching flycheck.

Verification

Ran the backend for real:

  • local PHPStan, unmodified and modified (editor-mode temp file) buffers: 2 and 3 diagnostics, each with identifier/tip, phpstan--ignorable-errors populated ((4 "function.notFound") (7 "constant.notFound") …).
  • Apple container: 2 diagnostics with identifiers — confirms container path normalization (config and target rewritten to /app/…) and that the STDERR progress is skipped.
  • A stopped Docker daemon now shows up as a warning diagnostic rather than silently nothing — the no-JSON fallback in action.

test/flymake-phpstan-test.el adds ERT coverage (message building, metadata toggle, STDERR-prefixed and no-JSON shapes, the ignorable-errors side effect); each test was checked to fail when its behaviour is reverted. 21/21 pass on system Emacs and Emacs 27.2; flymake-phpstan.el compiles warning-free on both.

Follow-up (not in this PR)

While testing I found that phpstan--parse-json represents JSON false as :false, which is truthy in Elisp — so a non-ignorable message is currently treated as ignorable by both backends (identifier shown, offered to phpstan-insert-ignore). That's a shared, pre-existing bug in the parser; I left it out of this PR to keep the flymake change focused and filed it separately. This PR matches flycheck's current behaviour exactly.

`flymake-phpstan' asked PHPStan for the `raw' format and scraped
`file:line:message' with a regexp, so it showed only the bare message and
none of the metadata `flycheck-phpstan' already surfaced.

Switch it to `--error-format=json' and parse with the shared
`phpstan--parse-json', so a Flymake session reaches parity with Flycheck:

  * each diagnostic carries the identifier and tip, gated by
    `flymake-phpstan-ignore-metadata-list' and joined with
    `flymake-phpstan-metadata-separator' (mirrors of the flycheck options);
  * `phpstan--ignorable-errors' and `phpstan--dumped-types' are refreshed
    in the source buffer, so `phpstan-insert-ignore' and
    `phpstan-copy-dumped-type' work from Flymake, not just Flycheck;
  * the JSON is located by the first line starting with `{', so the
    progress a container runtime writes to STDERR is skipped; and
  * output with no JSON report is surfaced -- silent for "No files found
    to analyse." in a modified buffer, a warning otherwise -- rather than
    scraped into nothing.

Diagnostics are now reported at `:error' level (they were `:warning'),
matching the severity flycheck uses.

Tests in test/flymake-phpstan-test.el cover message building, the metadata
toggle, the STDERR-prefixed and no-JSON output shapes, and the
ignorable-errors side effect; each was checked to fail when its behaviour
is reverted.  Verified end to end against local PHPStan and, through a
container, Apple `container'.
@zonuexe
zonuexe merged commit c46b6c8 into master Jul 17, 2026
9 checks passed
@zonuexe
zonuexe deleted the feature/flymake-json branch July 17, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant