emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 26759b9 027/495: support unused import detection f


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 26759b9 027/495: support unused import detection for *_test.go files
Date: Sat, 7 Aug 2021 09:04:37 -0400 (EDT)

branch: elpa/go-mode
commit 26759b90652e1ff240f1dff44fcd63e96ca08c7c
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    support unused import detection for *_test.go files
---
 go-mode.el | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 08a75b5..ad5f273 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -630,14 +630,18 @@ uncommented, otherwise a new import will be added."
       (go-root-and-paths)))) 'string<))
 
 (defun go-unused-imports-lines ()
-  ;; TODO handle *_test.gi files
-  (reverse (remove nil
-                   (mapcar
-                    (lambda (line)
-                      (if (string-match "^\\(.+\\):\\([[:digit:]]+\\): 
imported and not used: \".+\"$" line)
-                          (if (string= (file-truename (match-string 1 line)) 
buffer-file-truename)
-                              (string-to-number (match-string 2 line)))))
-                    (split-string (shell-command-to-string "go build -o 
/dev/null") "\n")))))
+  (let (cmd)
+    (if (string-match "_test\.go$" buffer-file-truename)
+        (setq cmd "go test -c")
+      (setq cmd "go build -o /dev/null"))
+    ;; TODO handle *_test.go files
+    (reverse (remove nil
+                     (mapcar
+                      (lambda (line)
+                        (if (string-match "^\\(.+\\):\\([[:digit:]]+\\): 
imported and not used: \".+\"$" line)
+                            (if (string= (file-truename (match-string 1 line)) 
buffer-file-truename)
+                                (string-to-number (match-string 2 line)))))
+                      (split-string (shell-command-to-string cmd) "\n"))))))
 
 (defun go-remove-unused-imports (arg)
   (interactive "P")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]