|
44 | 44 | ;; Usually it is defined dynamically by flycheck
|
45 | 45 | (defvar flycheck-phpstan-executable)
|
46 | 46 | (defvar flycheck-phpstan--temp-buffer-name "*Flycheck PHPStan*")
|
| 47 | +(defvar flycheck-phpstan--output-filter-added nil) |
| 48 | +(defconst flycheck-phpstan--nofiles-message (eval-when-compile (regexp-quote "[ERROR] No files found to analyse."))) |
47 | 49 |
|
48 | 50 | (defcustom flycheck-phpstan-ignore-metadata-list nil
|
49 | 51 | "Set of metadata items to ignore in PHPStan messages for Flycheck."
|
|
57 | 59 | :safe #'stringp
|
58 | 60 | :group 'phpstan)
|
59 | 61 |
|
| 62 | +(defun flycheck-phpstan--suppress-no-files-error (next checker exit-status files output callback cwd) |
| 63 | + "Suppress Flycheck errors if PHPStan reports no files in a modified buffer. |
| 64 | +
|
| 65 | +This function is intended to be used as an :around advice for |
| 66 | +`flycheck-finish-checker-process'. |
| 67 | +
|
| 68 | +It prevents Flycheck from displaying an error when: |
| 69 | +- CHECKER is `phpstan', |
| 70 | +- the current buffer is modified, |
| 71 | +- and OUTPUT contains the message `flycheck-phpstan--nofiles-message'. |
| 72 | +
|
| 73 | +NEXT, EXIT-STATUS, FILES, OUTPUT, CALLBACK, and CWD are the original arguments |
| 74 | +passed to `flycheck-finish-checker-process'." |
| 75 | + (unless (and (eq checker 'phpstan) |
| 76 | + (buffer-modified-p) |
| 77 | + (string-match-p flycheck-phpstan--nofiles-message output)) |
| 78 | + (funcall next checker exit-status files output callback cwd))) |
| 79 | + |
60 | 80 | (defun flycheck-phpstan--enabled-and-set-variable ()
|
61 | 81 | "Return path to phpstan configure file, and set buffer execute in side effect."
|
62 | 82 | (let ((enabled (phpstan-enabled)))
|
|
71 | 91 | (and (stringp (car-safe phpstan-executable))
|
72 | 92 | (listp (cdr-safe phpstan-executable)))
|
73 | 93 | (null phpstan-executable)))
|
| 94 | + (unless flycheck-phpstan--output-filter-added |
| 95 | + (advice-add 'flycheck-finish-checker-process |
| 96 | + :around #'flycheck-phpstan--suppress-no-files-error) |
| 97 | + (setq flycheck-phpstan--output-filter-added t)) |
74 | 98 | (setq-local flycheck-phpstan-executable (car (phpstan-get-executable-and-args)))))))
|
75 | 99 |
|
76 | 100 | (defun flycheck-phpstan-parse-output (output &optional _checker _buffer)
|
|
0 commit comments