Skip to content

Instantly share code, notes, and snippets.

@dsedivec
Forked from abo-abo/flycheck-ruff.el
Last active February 22, 2025 15:20
Show Gist options
  • Save dsedivec/65eff752ec3aa3b652977c6e681bd609 to your computer and use it in GitHub Desktop.
Save dsedivec/65eff752ec3aa3b652977c6e681bd609 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"
"check"
"--output-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 python-ts-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))))))
@chookity-pokk
Copy link

Nevermind, the problem was I apparently had ruff installed with both pip and homebrew so it was using the pip version which was very out of date. So adding the homebrew one to the exec path fixed the issue. Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment