Skip to content

Commit

Permalink
fix(emacs): don't explode if quick-lint-js reports a warning
Browse files Browse the repository at this point in the history
If quick-lint-js prints a warning for whatever reason, the warning
output is mixed with emacs-lisp output. This causes our Flymake code
to parse the output incorrectly, leading to confusing error messages
for users.

Fix the output confusion by forwarding warning output (stderr) to
Flymake's log, leaving the emacs-lisp output (stdout) cleanly
parsable.
  • Loading branch information
strager committed Oct 18, 2023
1 parent efeebfc commit e0ab6e1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugin/emacs/flymake-quicklintjs.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ REPORT-FN is Flymake's callback."
(when (process-live-p flymake-quicklintjs--proc)
(kill-process flymake-quicklintjs--proc))
(let ((src-buf (current-buffer))
(output-buf (generate-new-buffer " *flymake-quicklintjs*")))
(stdout-buf (generate-new-buffer "*flymake-quicklintjs*"))
(stderr-buf (generate-new-buffer "*flymake-quicklintjs-stderr*")))
(setq flymake-quicklintjs--proc
(make-process
:name "flymake-quicklintjs"
:connection-type 'pipe
:noquery t
:buffer output-buf
:buffer stdout-buf
:stderr stderr-buf
:command `(,flymake-quicklintjs-program
,@(let ((file (buffer-file-name)))
(if file
Expand All @@ -81,7 +83,11 @@ REPORT-FN is Flymake's callback."
(unwind-protect
(when (and (eq 'exit (process-status p))
(eq p flymake-quicklintjs--proc))
(with-current-buffer output-buf
(with-current-buffer stderr-buf
(flymake-log :warning "%S"
(buffer-substring-no-properties
(point-min) (point-max))))
(with-current-buffer stdout-buf
(let ((diags (flymake-quicklintjs--make-diagnostics
src-buf
(car (read-from-string
Expand All @@ -96,7 +102,8 @@ REPORT-FN is Flymake's callback."
(point-min) (progn (goto-char (point-min))
(line-end-position))))))))
(unless (process-live-p p)
(kill-buffer output-buf))))))
(kill-buffer stdout-buf)
(kill-buffer stderr-buf))))))
(process-send-region flymake-quicklintjs--proc (point-min) (point-max))
(process-send-eof flymake-quicklintjs--proc)))

Expand Down

0 comments on commit e0ab6e1

Please sign in to comment.