Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save andreasjansson/1cb4be3ad7c5b6b02e0b to your computer and use it in GitHub Desktop.

Select an option

Save andreasjansson/1cb4be3ad7c5b6b02e0b to your computer and use it in GitHub Desktop.
pylint-ignore
(defun pylint-ignore ()
(interactive)
(save-excursion
(let* ((err (fly-get-err-at-point))
(err-str (flymake-ler-text err))
(err-code (nth 0 (fly-parse-message err-str))))
(end-of-line)
(insert (concat " # pylint: disable=" err-code)))))
(defun fly-parse-message (str)
(string-match "\\[\\([^],]+\\)\\(?:, [^]]+\\)\\] \\(.+\\)" str)
(let ((code (match-string 1 str))
(message (match-string 2 str)))
(list code message)))
(defun fly-get-err-at-point ()
(let ((err nil)
(line-no (line-number-at-pos)))
(dolist (elem flymake-err-info)
(if (eq (car elem) line-no)
(setq err (car (second elem)))))
err))
; requires pylint==0.28
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pylint" (list "-i" "y" "-d" "C" "-d" "R" "-d" "I" "-r" "n" "-f" "parseable" local-file))
))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment