Browse Source

Fix and enable python-black flycheck checker

master
10sr 5 years ago
parent
commit
34946093c8
Signed by: 10sr GPG Key ID: 7BEC428194130EB2
1 changed files with 28 additions and 4 deletions
  1. +28
    -4
      emacs.el

+ 28
- 4
emacs.el View File

@@ -2030,12 +2030,25 @@ initializing."

(require 'flycheck)

'(flycheck-define-checker python-black
(flycheck-define-checker python-black
"A Python style checker."
:command ("python3"
"-m" "black"
(config-file "--config" flycheck-black)
"--check" source)
:error-parser my-flycheck-parse-any-error
:enabled (lambda ()
(or (not (flycheck-python-needs-module-p 'python-black))
(flycheck-python-find-module 'python-black "black")))
:verify (lambda (_) (flycheck-python-verify-module 'python-black "black"))
:modes python-mode)

'(flycheck-define-checker python-black-diff
"A Python style checker."
:command ("python3"
"-m" "black"
(config-file "--config" flycheck-black)
"--check" source)
"--diff" source)
:error-parser my-flycheck-parse-unified-diff
:enabled (lambda ()
(or (not (flycheck-python-needs-module-p 'python-black))
@@ -2050,8 +2063,19 @@ initializing."
'python-black)

(defun my-flycheck-parse-any-error (output checker buffer)
"Flycheck parser to check if OUTPUT is not empty."
())
"Flycheck parser to check if reformat is required."
(with-temp-buffer
(insert output)
(goto-char (point-min))
(when (re-search-forward "^would reformat .*$" nil t)
(list (flycheck-error-new-at
(point-min)
nil
'error
;;(format "Black: %s" (match-string 0))
"Black: would reformat buffer"
:buffer buffer
:checker checker)))))

(defun my-flycheck-parse-unified-diff (output checker buffer)
"Flycheck parser to parse diff output."


Loading…
Cancel
Save