Skip to content

Commit 3c489cf

Browse files
committed
Add support error identifier to flycheck-phpstan.el
1 parent daa30e3 commit 3c489cf

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

flycheck-phpstan.el

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@
4545
(defvar flycheck-phpstan-executable)
4646
(defvar flycheck-phpstan--temp-buffer-name "*Flycheck PHPStan*")
4747

48+
49+
(defcustom flycheck-phpstan-ignore-metadata-list nil
50+
"Set of metadata items to ignore in PHPStan messages for Flycheck."
51+
:type '(set (const identifier)
52+
(const tip))
53+
:group 'phpstan)
54+
55+
(defcustom flycheck-phpstan-metadata-separator "\n"
56+
"Separator of PHPStan message and metadata."
57+
:type 'string
58+
:safe #'stringp
59+
:group 'phpstan)
60+
4861
(defun flycheck-phpstan--enabled-and-set-variable ()
4962
"Return path to phpstan configure file, and set buffer execute in side effect."
5063
(let ((enabled (phpstan-enabled)))
@@ -77,11 +90,21 @@
7790
(let ((data (phpstan--parse-json json-buffer)))
7891
(cl-loop for (file . entry) in (flycheck-phpstan--plist-to-alist (plist-get data :files))
7992
append (cl-loop for messages in (plist-get entry :messages)
80-
for text = (let ((msg (plist-get messages :message))
81-
(tip (plist-get messages :tip)))
82-
(if tip
83-
(concat msg "\n" phpstan-tip-message-prefix tip)
84-
msg))
93+
for text = (let* ((msg (plist-get messages :message))
94+
(ignorable (plist-get messages :ignorable))
95+
(identifier (unless (memq 'identifier flycheck-phpstan-ignore-metadata-list)
96+
(plist-get messages :identifier)))
97+
(tip (unless (memq 'tip flycheck-phpstan-ignore-metadata-list)
98+
(plist-get messages :tip)))
99+
(lines (list (when (and identifier ignorable)
100+
(concat phpstan-identifier-prefix identifier))
101+
(when tip
102+
(concat phpstan-tip-message-prefix tip))))
103+
(lines (cl-remove-if #'null lines)))
104+
(if (null lines)
105+
msg
106+
(concat msg flycheck-phpstan-metadata-separator
107+
(mapconcat #'identity lines "\n"))))
85108
collect (flycheck-error-new-at (plist-get messages :line)
86109
nil 'error text
87110
:filename file)))))

phpstan.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
:safe #'stringp
130130
:group 'phpstan)
131131

132+
(defcustom phpstan-identifier-prefix "🪪 "
133+
"Prefix of PHPStan error identifier."
134+
:type 'string
135+
:safe #'stringp
136+
:group 'phpstan)
137+
132138
(defcustom phpstan-enable-remote-experimental nil
133139
"Enable PHPStan analysis remotely by TRAMP.
134140

0 commit comments

Comments
 (0)