summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAugusto Stoffel <arstoffel@gmail.com>2022-08-13 17:39:57 +0200
committerStefan Kangas <stefankangas@gmail.com>2022-08-19 14:59:27 +0200
commit275cef9e06b406c6e68ec5cf9fe882ab0fde8999 (patch)
treefce3e37a12e2f4874c156acc77c5c2fdfc13548b
parentec347aec0fc7d2d3e6603b6694d9978cb9fcb9e9 (diff)
downloademacs-275cef9e06b406c6e68ec5cf9fe882ab0fde8999.tar.gz
emacs-275cef9e06b406c6e68ec5cf9fe882ab0fde8999.tar.bz2
emacs-275cef9e06b406c6e68ec5cf9fe882ab0fde8999.zip
python.el: Adjustments to Flymake backend
* lisp/progmodes/python (python-flymake-command): Advertise possiblity to use pylint. (python-flymake-command-output-pattern): Make compatible with recent versions of pyflakes. (Bug#53913)
-rw-r--r--lisp/progmodes/python.el14
-rw-r--r--test/lisp/progmodes/python-tests.el34
2 files changed, 43 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 285a57348e0..5fffb4b7d3d 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5648,9 +5648,13 @@ returned as is."
This is a non empty list of strings, the checker tool possibly followed by
required arguments. Once launched it will receive the Python source to be
checked as its standard input.
-To use `flake8' you would set this to (\"flake8\" \"-\")."
+To use `flake8' you would set this to (\"flake8\" \"-\").
+To use `pylint' you would set this to (\"pylint\" \"--from-stdin\" \"stdin\")."
:version "26.1"
- :type '(repeat string))
+ :type '(choice (const :tag "Pyflakes" ("pyflakes"))
+ (const :tag "Flake8" ("flake8" "-"))
+ (const :tag "Pylint" ("pylint" "--from-stdin" "stdin"))
+ (repeat :tag "Custom command" string)))
;; The default regexp accommodates for older pyflakes, which did not
;; report the column number, and at the same time it's compatible with
@@ -5658,7 +5662,7 @@ To use `flake8' you would set this to (\"flake8\" \"-\")."
;; TYPE
(defcustom python-flymake-command-output-pattern
(list
- "^\\(?:<?stdin>?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$"
+ "^\\(?:<?stdin>?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):?\\)? \\(?3:.*\\)$"
1 2 nil 3)
"Specify how to parse the output of `python-flymake-command'.
The value has the form (REGEXP LINE COLUMN TYPE MESSAGE): if
@@ -5670,7 +5674,6 @@ MESSAGE'th gives the message text itself.
If COLUMN or TYPE are nil or that index didn't match, that
information is not present on the matched line and a default will
be used."
- :version "26.1"
:type '(list regexp
(integer :tag "Line's index")
(choice
@@ -5679,7 +5682,8 @@ be used."
(choice
(const :tag "No type" nil)
(integer :tag "Type's index"))
- (integer :tag "Message's index")))
+ (integer :tag "Message's index"))
+ :version "29.1")
(defcustom python-flymake-msg-alist
'(("\\(^redefinition\\|.*unused.*\\|used$\\)" . :warning))
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 0904dfc9639..a11716a7b53 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -6300,6 +6300,40 @@ buffer with overlapping strings."
a = 1
")))
+
+;;; Flymake
+
+(ert-deftest python-tests--flymake-command-output-pattern ()
+ (pcase-let ((`(,patt ,line ,col ,type ,msg)
+ python-flymake-command-output-pattern))
+ ;; Pyflakes output as of version 2.4.0
+ (let ((output "<stdin>:12:34 'a.b.c as d' imported but unused"))
+ (string-match patt output)
+ (should (equal (match-string line output) "12"))
+ (when col (should (equal (match-string col output) "34")))
+ (should (equal (match-string msg output)
+ "'a.b.c as d' imported but unused")))
+ ;; Flake8 output as of version 4.0.1
+ (let ((output "stdin:12:34: F401 'a.b.c as d' imported but unused"))
+ (string-match patt output)
+ (should (equal (match-string line output) "12"))
+ (when col (should (equal (match-string col output) "34")))
+ (when type (should (equal (match-string type output) "F401")))
+ (should (equal (match-string msg output)
+ (if type
+ "'a.b.c as d' imported but unused"
+ "F401 'a.b.c as d' imported but unused"))))
+ ;; Pylint output as of version 2.14.5
+ (let ((output "stdin:12:34: W0611: Unused import a.b.c (unused-import)"))
+ (string-match patt output)
+ (should (equal (match-string line output) "12"))
+ (when col (should (equal (match-string col output) "34")))
+ (when type (should (equal (match-string type output) "W0611")))
+ (should (equal (match-string msg output)
+ (if type
+ "Unused import a.b.c (unused-import)"
+ "W0611: Unused import a.b.c (unused-import)"))))))
+
(provide 'python-tests)
;;; python-tests.el ends here