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

    [Fix #2169] Parse Ruff's severity-tagged output format
    
    Ruff 0.15.7 in preview mode wraps the rule code in a severity tag
    (e.g. "error[F401]" instead of "F401"), which no longer matched the
    python-ruff warning pattern and made all of its errors disappear.
    Accept the optional severity wrapper.
---
 CHANGES.rst                         |  2 ++
 flycheck.el                         |  6 +++++-
 test/specs/languages/test-python.el | 24 ++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 9c7132efb1..0bf93ddfb3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2,6 +2,8 @@
 =======================
 
 - Add ``neocaml-opam-mode`` support to the ``opam`` checker.
+- [#2169]: Parse the severity-tagged output format introduced by Ruff 0.15.7
+  in preview mode (e.g. ``error[F401]`` instead of ``F401``).
 
 36.0 (2026-02-19)
 ======================
diff --git a/flycheck.el b/flycheck.el
index bc41f0fd78..e18d1f9a30 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -10770,7 +10770,11 @@ See URL `https://docs.astral.sh/ruff/'."
           line-end)
    (warning line-start
             (or "-" (file-name)) ":" line ":" (optional column ":") " "
-            (id (one-or-more (any alpha)) (one-or-more digit)) " "
+            ;; ruff >= 0.15.7 in preview mode wraps the rule code in a
+            ;; severity tag, e.g. "error[F401]" instead of just "F401"
+            (optional (one-or-more (any alpha)) "[")
+            (id (one-or-more (any alpha)) (one-or-more digit))
+            (optional "]") " "
             (message (one-or-more not-newline))
             line-end))
   :error-explainer flycheck-python-ruff-explainer
diff --git a/test/specs/languages/test-python.el 
b/test/specs/languages/test-python.el
index b45344f6b6..ebdf162415 100644
--- a/test/specs/languages/test-python.el
+++ b/test/specs/languages/test-python.el
@@ -67,6 +67,30 @@
        '(22 1 error "Undefined name `antigravity`" :id "F821"
            :checker python-ruff))))
 
+  (describe "python-ruff error patterns"
+    ;; Run synthetic output through the patterns so we cover formats from
+    ;; ruff versions other than the one installed in CI.
+    (it "parses the plain rule code format (ruff < 0.15.7)"
+      (flycheck-buttercup-with-temp-buffer
+        (expect
+         (flycheck-parse-output
+          "-:1:8: F401 `os` imported but unused\n"
+          'python-ruff (current-buffer))
+         :to-be-equal-flycheck-errors
+         (list (flycheck-error-new-at
+                1 8 'warning "`os` imported but unused"
+                :id "F401" :checker 'python-ruff)))))
+    (it "parses the severity-tagged format (ruff >= 0.15.7 preview)"
+      (flycheck-buttercup-with-temp-buffer
+        (expect
+         (flycheck-parse-output
+          "-:1:8: error[F401] `os` imported but unused\n"
+          'python-ruff (current-buffer))
+         :to-be-equal-flycheck-errors
+         (list (flycheck-error-new-at
+                1 8 'warning "`os` imported but unused"
+                :id "F401" :checker 'python-ruff))))))
+
   (flycheck-buttercup-def-checker-test python-pylint python nil
     (let ((flycheck-disabled-checkers '(python-flake8 python-mypy))
           (flycheck-python-pylint-executable "python3"))

Reply via email to