Skip to content

Commit

Permalink
feat(flymake): add Bandit backend for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Nov 19, 2023
1 parent 8db462e commit c326db8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion modules/me-checkers.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,33 @@

(use-package flymake-quickdef
:straight t
:autoload flymake-quickdef-backend)
:autoload flymake-quickdef-backend
:hook ((python-mode python-ts-mode) . +flymake-bandit-load)
:init
(defun +flymake-bandit-load ()
(add-hook 'flymake-diagnostic-functions #'flymake-check-bandit nil t))
:config
;; Add Bandit support for Python (example from https://github.com/karlotness/flymake-quickdef)
(flymake-quickdef-backend flymake-bandit
:pre-let ((bandit-exec (executable-find "bandit")))
:pre-check (unless bandit-exec (error "Cannot find bandit executable"))
:write-type 'file
:proc-form (list bandit-exec "--format" "custom" "--msg-template" "diag:{line} {severity} {test_id}: {msg}" fmqd-temp-file)
:search-regexp "^diag:\\([[:digit:]]+\\) \\(HIGH\\|LOW\\|MEDIUM\\|UNDEFINED\\) \\([[:alpha:]][[:digit:]]+\\): \\(.*\\)$"
:prep-diagnostic
(let* ((lnum (string-to-number (match-string 1)))
(severity (match-string 2))
(code (match-string 3))
(text (match-string 4))
(pos (flymake-diag-region fmqd-source lnum))
(beg (car pos))
(end (cdr pos))
(type (cond
((string= severity "HIGH") :error)
((string= severity "MEDIUM") :warning)
(t :note)))
(msg (format "%s (%s)" text code)))
(list fmqd-source beg end type msg))))


(provide 'me-checkers)
Expand Down

0 comments on commit c326db8

Please sign in to comment.