Bladeren bron

Fix and enable python-black flycheck checker

master
10sr 5 jaren geleden
bovenliggende
commit
34946093c8
Getekend door: 10sr GPG sleutel-ID: 7BEC428194130EB2
1 gewijzigde bestanden met toevoegingen van 28 en 4 verwijderingen
  1. +28
    -4
      emacs.el

+ 28
- 4
emacs.el Bestand weergeven

@@ -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."


Laden…
Annuleren
Opslaan