| @@ -2030,12 +2030,25 @@ initializing." | |||||
| (require 'flycheck) | (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." | "A Python style checker." | ||||
| :command ("python3" | :command ("python3" | ||||
| "-m" "black" | "-m" "black" | ||||
| (config-file "--config" flycheck-black) | (config-file "--config" flycheck-black) | ||||
| "--check" source) | |||||
| "--diff" source) | |||||
| :error-parser my-flycheck-parse-unified-diff | :error-parser my-flycheck-parse-unified-diff | ||||
| :enabled (lambda () | :enabled (lambda () | ||||
| (or (not (flycheck-python-needs-module-p 'python-black)) | (or (not (flycheck-python-needs-module-p 'python-black)) | ||||
| @@ -2050,8 +2063,19 @@ initializing." | |||||
| 'python-black) | 'python-black) | ||||
| (defun my-flycheck-parse-any-error (output checker buffer) | (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) | (defun my-flycheck-parse-unified-diff (output checker buffer) | ||||
| "Flycheck parser to parse diff output." | "Flycheck parser to parse diff output." | ||||