Skip to content

Commit c0c12b6

Browse files
committed
Remove unused imports of the form 'import foo.bar as baz'
Previously we would end up with 'import foo.'.
1 parent 5435640 commit c0c12b6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pyimport.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ FLYCHECK-MESSAGE should take the form \"'foo' imported but unused\"."
150150
(s-match "'\\(.*\\)' imported but unused")
151151
-last-item
152152
(s-split (rx "."))
153+
-last-item
154+
(s-split (rx " as "))
153155
-last-item))
154156

155157
(defun pyimport--remove-on-line (text)

test/pyimport-test.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@
5757
(should (equal (get-text-property 0 'pyimport-path (-first-item lines))
5858
"my-buffer")))))))
5959

60+
(ert-deftest extract-unused-var ()
61+
(should
62+
(equal
63+
(pyimport--extract-unused-var "'foo' imported but unused")
64+
"foo"))
65+
(should
66+
(equal
67+
(pyimport--extract-unused-var "'foo.bar' imported but unused")
68+
"bar"))
69+
(should
70+
(equal
71+
(pyimport--extract-unused-var "'foo.bar as xxx' imported but unused")
72+
"xxx")))
73+
6074
(ert-deftest same-module ()
6175
(should
6276
(pyimport--same-module

0 commit comments

Comments
 (0)