- Emacs Lisp 100%
Capture `flymake-ruff-program` and `flymake-ruff-program-args` before entering `with-temp-buffer`, where the current buffer changes and buffer-local values would be lost. This enables compatibility with packages like emacs-pet that set buffer-local values for Python tool paths. |
||
|---|---|---|
| .gitignore | ||
| flymake-ruff.el | ||
| LICENSE | ||
| README.md | ||
flymake-ruff
Flymake plugin to run a linter for python buffers using ruff
Make sure you have at least
ruff0.1.0version because there is a breaking change in the output format flag If you are using a version ofruff<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)