summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Marlow <graham@mgmarlow.com>2023-08-26 10:02:32 -0700
committerGraham Marlow <graham@mgmarlow.com>2023-08-26 10:02:32 -0700
commitd0774403fe96d88bd629d0825ffca46a1786d697 (patch)
treea6ba9ed0e04fd536fb48c4748c234981c1dbf739
parent42078c60bf2d39d509bc3f81a1973e0522d597e7 (diff)
downloadflymake-clippy-d0774403fe96d88bd629d0825ffca46a1786d697.tar.gz
Add support for codes in error messages
Modify the Clippy regexp to accept error codes, e.g. "error[E0407]". Co-authored-by: Eugeny Volobuev <j21@eml.cc> Co-authored-by: Graham Marlow <graham@mgmarlow.com>
-rw-r--r--flymake-clippy-test.el39
-rw-r--r--flymake-clippy.el6
2 files changed, 41 insertions, 4 deletions
diff --git a/flymake-clippy-test.el b/flymake-clippy-test.el
index 0cc3018..9f2c527 100644
--- a/flymake-clippy-test.el
+++ b/flymake-clippy-test.el
@@ -3,6 +3,12 @@
(require 'flymake-clippy)
(require 'ert)
+(defmacro with-text (text &rest body)
+ `(with-temp-buffer
+ (insert ,text)
+ (goto-char 0)
+ ,@body))
+
(defun run-regexp ()
(set-match-data nil)
(search-forward-regexp (flymake-clippy--build-regexp) nil t)
@@ -10,8 +16,8 @@
(match-string 2)
(match-string 3)))
-(ert-deftest clippy-test-regexp ()
- "Tests regexp matches diagnostic information."
+(ert-deftest clippy-test-fixture ()
+ "Tests fixture diagnostics."
(should (equal (with-temp-buffer
(insert-file-contents "./test/fixture.txt")
(run-regexp))
@@ -27,3 +33,32 @@
(run-regexp)
(run-regexp))
'("warning: unused variable: `user`" "src/foobar/user.rs" "42"))))
+
+(defvar warning-text
+"warning: unused variable: `user`
+ --> src/database/foo.rs:42:9
+ |
+42 | user: &User,
+ | ^^^^ help: if this is intentional, prefix it with an underscore: `_user`
+ |
+ = note: `#[warn(unused_variables)]` on by default")
+
+(ert-deftest clippy-test-warnings ()
+ "Tests warning diagnostics."
+ (should (equal (with-text warning-text (run-regexp))
+ '("warning: unused variable: `user`" "src/database/foo.rs" "42"))))
+
+(defvar error-text
+"error: expected one of `!` or `::`, found foobar
+ --> src/main.rs:20:9")
+
+(defvar error-text-with-error-num
+"error[E0407]: method `build_string` is not defined
+ --> src/features.rs:106:5")
+
+(ert-deftest clippy-test-errors ()
+ "Tests error diagnostics."
+ (should (equal (with-text error-text (run-regexp))
+ '("error: expected one of `!` or `::`, found foobar" "src/main.rs" "20")))
+ (should (equal (with-text error-text-with-error-num (run-regexp))
+ '("error[E0407]: method `build_string` is not defined" "src/features.rs" "106"))))
diff --git a/flymake-clippy.el b/flymake-clippy.el
index 7925362..e9dfffc 100644
--- a/flymake-clippy.el
+++ b/flymake-clippy.el
@@ -5,7 +5,7 @@
;; Author: Graham Marlow <info@mgmarlow.com>
;; Keywords: tools
;; URL: https://sr.ht/~mgmarlow/flymake-clippy/
-;; Version: 1.0.0
+;; Version: 1.0.1
;; Package-Requires: ((emacs "26.1"))
;; This program is free software; you can redistribute it and/or modify
@@ -40,7 +40,9 @@
"Regexp for Clippy output."
(rx (seq line-start
;; Message
- (group (or "warning:" "error:")
+ (group (or "warning" "error")
+ (zero-or-one (seq "[" (repeat 5 alphanumeric) "]"))
+ ":"
(zero-or-more nonl))
"\n"
(zero-or-more nonl)