flymake plugin for ruff linter
  • Emacs Lisp 100%
Find a file
Andreas Jonsson ef4a6caed7
Add Ruff rule doc lookup helper to README (#31)
* README.md: Add Ruff rule doc lookup helper to README

* flymake-ruff.el: Add command to browse Ruff rule docs from diagnostics

* README.md: Clarify and condense Ruff rule doc instructions
2026-06-15 22:27:39 -06:00
.gitignore Add .gitignore (#3) 2023-06-18 10:46:44 -05:00
flymake-ruff.el Add Ruff rule doc lookup helper to README (#31) 2026-06-15 22:27:39 -06:00
LICENSE Initial commit 🚀 2023-01-28 11:39:13 -06:00
README.md Add Ruff rule doc lookup helper to README (#31) 2026-06-15 22:27:39 -06:00

flymake-ruff

MELPA

Flymake plugin to run a linter for python buffers using ruff

Make sure you have at least ruff 0.1.0 version because there is a breaking change in the output format flag If you are using a version of ruff < 0.5.0, set flymake-ruff-program-args to '("--output-format" "text" "--exit-zero" "--quiet" "-")

Installation

Cloning the repo

Clone this repo somewhere, and add this to your config:

(add-to-list 'load-path "path where the repo was cloned")

(require 'flymake-ruff)
(add-hook 'python-mode-hook #'flymake-ruff-load)

Using use-package

(use-package flymake-ruff
  :ensure t
  :hook (python-mode . flymake-ruff-load))

Using straight.el

(use-package flymake-ruff
  :straight (flymake-ruff
             :type git
             :host github
             :repo "erickgnavar/flymake-ruff"))

Using flymake-ruff with eglot

To use flymake-ruff together with eglot, you should add flymake-ruff-load to eglot-managed-mode-hook instead. For example:

(add-hook 'eglot-managed-mode-hook 'flymake-ruff-load)

Or, if you use use-package:

(use-package flymake-ruff
  :ensure t
  :hook (eglot-managed-mode . flymake-ruff-load))

Excluding Pyright diagnostic notes

Pyright has some diagnostic notes that overlap with diagnostics provided by ruff. These diagnostic notes can't be disabled via Pyright's config, but you can exclude them by adding a filter to eglot--report-to-flymake. For example, to remove Pyright's "variable not accessed" notes, add the following:

(defun my-filter-eglot-diagnostics (diags)
    "Drop Pyright 'variable not accessed' notes from DIAGS."
    (list (seq-remove (lambda (d)
                        (and (eq (flymake-diagnostic-type d) 'eglot-note)
                             (s-starts-with? "Pyright:" (flymake-diagnostic-text d))
                             (s-ends-with? "is not accessed" (flymake-diagnostic-text d))))
                      (car diags))))

(advice-add 'eglot--report-to-flymake :filter-args #'my-filter-eglot-diagnostics)

Jump to Ruff rule documentation

The flymake-ruff-goto-doc function scans the Flymake diagnostics buffer at point for a "RULE123"-style code and opens its reference page at https://docs.astral.sh/ruff/rules.

To bind it to a key in Flymake diagnostics buffers:

(with-eval-after-load 'flymake
  (define-key flymake-diagnostics-buffer-mode-map
              (kbd "M-RET") #'flymake-ruff-goto-doc)
  (define-key flymake-project-diagnostics-mode-map
              (kbd "M-RET") #'flymake-ruff-goto-doc))

Now, when youre in any Flymake diagnostics buffer, pressing M-RET on a line containing a Ruff rule will open the corresponding rule page in your browser.