Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ All notable changes of the `phpstan.el` are documented in this file using the [K
* Fix `phpstan-executable` in the `(STRING . (ARGUMENTS ...))` form dropping the command name, which made the first *argument* run as the program (`("docker" "run" ...)` executed `run`).
* Fix `phpstan-get-command-args` destructively modifying its inputs with `nconc`. Each call appended the PHPStan arguments onto the caller's own list, growing `phpstan-executable` in the `(STRING . (ARGUMENTS ...))` form on every check, and appending `"--"` to `phpstan-generate-baseline-options` on every `phpstan-generate-baseline`.
* Fix Flycheck getting stuck on a syntax check when PHPStan reported no files to analyse in a modified buffer. The check now finishes with an empty result instead of never reporting a status.
* Fix the analyzed file being passed to a containerized PHPStan as a host path. `flycheck-phpstan` reported no errors at all with `(phpstan-executable . docker)`, because PHPStan answered `Path /Users/... does not exist`. `flymake-phpstan` was affected for unmodified buffers.
* Fix the `--tmp-file` copy being created in the system temporary directory when running containerized, where the container cannot see it.
* Fix the JSON report being ignored when the container runtime prefixes it with progress output on STDERR, which made every check with `(phpstan-executable . container)` report no errors.
* Fix `flycheck-phpstan` silently discarding the fallback warning when PHPStan produced no JSON report, hiding failures such as a broken configuration file behind a clean buffer.

## [0.9.0]

Expand Down
32 changes: 20 additions & 12 deletions flycheck-phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,26 @@
;; Parsing PHPStan output:
(defun flycheck-phpstan-parse-output (output &optional _checker _buffer)
"Parse PHPStan errors from OUTPUT."
(let* ((json-buffer (with-current-buffer (flycheck-phpstan--temp-buffer)
(erase-buffer)
(insert output)
(current-buffer)))
(data (if (string-prefix-p "{" output)
(phpstan--parse-json json-buffer)
(list (flycheck-error-new-at 1 1 'warning (string-trim output)))))
(errors (phpstan--plist-to-alist (plist-get data :files))))
(unless phpstan-disable-buffer-errors
(phpstan-update-ignorebale-errors-from-json-buffer errors))
(phpstan-update-dumped-types errors)
(flycheck-phpstan--build-errors errors)))
;; Look for a line starting with `{', the same condition
;; `phpstan--parse-json' acts on: it skips everything before that line so
;; that output written to STDERR is ignored, since the checker process
;; merges STDERR into STDOUT. Anchoring at the start of OUTPUT instead
;; would miss the JSON whenever the runtime prefixes it, as Apple container
;; does with its progress report.
(if (not (string-match-p "^{" output))
;; PHPStan produced no report at all, so OUTPUT is a failure of some
;; kind. Surface it rather than reporting a clean buffer.
(list (flycheck-error-new-at 1 1 'warning (string-trim output)))
(let* ((json-buffer (with-current-buffer (flycheck-phpstan--temp-buffer)
(erase-buffer)
(insert output)
(current-buffer)))
(data (phpstan--parse-json json-buffer))
(errors (phpstan--plist-to-alist (plist-get data :files))))
(unless phpstan-disable-buffer-errors
(phpstan-update-ignorebale-errors-from-json-buffer errors))
(phpstan-update-dumped-types errors)
(flycheck-phpstan--build-errors errors))))

(defun flycheck-phpstan--temp-buffer ()
"Return a temporary buffer for decode JSON."
Expand Down
5 changes: 3 additions & 2 deletions flymake-phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@

(defun flymake-phpstan--create-temp-file ()
"Create temp file and return the path."
(phpstan-normalize-path
(flymake-proc-init-create-temp-buffer-copy 'flymake-proc-create-temp-inplace)))
;; `phpstan-get-command-args' translates the path for the container mount
;; point, so return the path as it is on this side.
(flymake-proc-init-create-temp-buffer-copy 'flymake-proc-create-temp-inplace))

(defun flymake-phpstan (report-fn &rest _ignored-args)
"Flymake backend for PHPStan report using REPORT-FN."
Expand Down
24 changes: 18 additions & 6 deletions phpstan.el
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,27 @@ it returns the value of `SOURCE' as it is."
(phpstan-use-xdebug-option (list "--xdebug")))
options
(when editor
(let ((original-file (plist-get editor :original-file)))
(let* ((original-file (plist-get editor :original-file))
;; PHPStan may see the project through a mount point, so
;; every path handed to it has to be translated, exactly
;; like the config file above.
(target-file (phpstan-normalize-path original-file)))
(cond
((funcall (plist-get editor :analyze-original) original-file)
(list "--" original-file))
(list "--" target-file))
((phpstan-editor-mode-available-p (car (phpstan-get-executable-and-args)))
(list "--tmp-file" (funcall (plist-get editor :temp-file))
"--instead-of" original-file
"--" original-file))
((list "--" (funcall (plist-get editor :inplace)))))))
;; A container only sees the project, so the temporary copy
;; has to be created inside it. `:temp-file' puts it in the
;; system temporary directory, which is not mounted.
(let ((temp-file (funcall (plist-get editor
(if (phpstan--container-executable-p)
:inplace
:temp-file)))))
(list "--tmp-file" (phpstan-normalize-path temp-file)
"--instead-of" target-file
"--" target-file)))
((list "--" (phpstan-normalize-path
(funcall (plist-get editor :inplace))))))))
(if editor args (cons "--" args)))))

(defun phpstan-update-ignorebale-errors-from-json-buffer (errors)
Expand Down
Loading