Skip to content

Instantly share code, notes, and snippets.

@lvii
Forked from abo-abo/flycheck-ruff.el
Created February 27, 2023 14:07
Show Gist options
  • Save lvii/b096d92bdfee98e4e6c267a56f529843 to your computer and use it in GitHub Desktop.
Save lvii/b096d92bdfee98e4e6c267a56f529843 to your computer and use it in GitHub Desktop.
Emacs ruff flycheck config
(require 'flycheck)
;; From https://github.com/flycheck/flycheck/issues/1974#issuecomment-1343495202
(flycheck-define-checker python-ruff
"A Python syntax and style checker using the ruff utility.
To override the path to the ruff executable, set
`flycheck-python-ruff-executable'.
See URL `http://pypi.python.org/pypi/ruff'."
:command ("ruff"
"--format=text"
(eval (when buffer-file-name
(concat "--stdin-filename=" buffer-file-name)))
"-")
:standard-input t
:error-filter (lambda (errors)
(let ((errors (flycheck-sanitize-errors errors)))
(seq-map #'flycheck-flake8-fix-error-level errors)))
:error-patterns
((warning line-start
(file-name) ":" line ":" (optional column ":") " "
(id (one-or-more (any alpha)) (one-or-more digit)) " "
(message (one-or-more not-newline))
line-end))
:modes python-mode)
;; Use something adapted to your config to add `python-ruff' to `flycheck-checkers'
;; This is an MVP example:
(setq python-mode-hook
(list (defun my-python-hook ()
(unless (bound-and-true-p org-src-mode)
(when (buffer-file-name)
(setq-local flycheck-checkers '(python-ruff))
(flycheck-mode))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment