branch: elpa/flycheck
commit 555a8c7b9fd4f57da31970ac23603b30b31e77d4
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Capture error codes in python-mypy checker
    
    Add --show-error-codes flag (explicit, default since mypy 0.900)
    and an error-filter that extracts error codes like [assignment]
    from the message into the error ID field.  This allows users to
    see, filter, and copy specific mypy error codes.
---
 flycheck.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/flycheck.el b/flycheck.el
index 66db404b4a..2de04a4614 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -10929,6 +10929,7 @@ See URL `https://github.com/microsoft/pyright'."
 See URL `https://mypy-lang.org/'."
   :command ("mypy"
             "--show-column-numbers"
+            "--show-error-codes"
             "--no-pretty"
             (config-file "--config-file" flycheck-python-mypy-config)
             (option "--cache-dir" flycheck-python-mypy-cache-dir)
@@ -10941,6 +10942,14 @@ See URL `https://mypy-lang.org/'."
             ": warning:" (message) line-end)
    (info line-start (file-name) ":" line (optional ":" column)
          ": note:" (message) line-end))
+  :error-filter
+  (lambda (errors)
+    (dolist (err errors)
+      (let ((msg (flycheck-error-message err)))
+        (when (and msg (string-match "\\(.*?\\)  \\[\\([^]]+\\)\\]\\'" msg))
+          (setf (flycheck-error-message err) (match-string 1 msg))
+          (setf (flycheck-error-id err) (match-string 2 msg)))))
+    errors)
   :working-directory flycheck-python-find-project-root
   :modes (python-mode python-ts-mode)
   ;; Ensure the file is saved, to work around

Reply via email to