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
;; 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
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
(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))
a = 1
")))
+\f
+;;; 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