-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ruff
#1974
Comments
I don't know enough about
(based on https://github.com/Wilfred/flycheck-pyflakes and the flake8 bits of |
@mhvk Seems work for me! |
Cool!! I use Spacemacs and it works for me. |
Woo! It's working great! It'd be so great if we had ruff's "quick fix" and "fix the whole buffer" features. Even after 36 years of emacs, I'm not elisp-enabled enough to knock that out quickly. :-( |
Something that might be an easy, incremental improvement is to add ruff to the UI menu (Python -> Checks -> Ruff). I'm not normally a menu guy, but this would be a nice add. |
Auto-fix would indeed be nice, but I'm afraid I'm not enough of an emacs expert to do that... |
@rpeck You can get ruff's auto-fix if you use Ruff as an lsp-server instead of as a flycheck-checker |
@vikigenius - that sounds very interesting! Do you have a snippet for enabling that? |
Well, I use doom emacs so it already has lsp mode pre enabled and auto configured. As long as the lsp-mode is able to find a package called ruff-lsp in your Path (I typically have it installed in my venv) it automatically starts ruff alongside any other python language servers you may have. |
Already noted that in the associated pull request: The (flycheck-def-config-file-var flycheck-python-ruff-config python-ruff
'("pyproject.toml" "ruff.toml" ".ruff.toml"))
(flycheck-define-checker python-ruff
"A Python syntax and style checker using the ruff.
To override the path to the ruff executable, set
`flycheck-python-ruff-executable'.
See URL `https://beta.ruff.rs/docs/'."
:command ("ruff"
"check"
(config-file "--config" flycheck-python-ruff-config)
"--output-format=text"
"--stdin-filename" source-original
"-")
: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)
:next-checkers ((warning . python-mypy)))
;; Python config: Use ruff + mypy.
(defun python-flycheck-setup ()
(progn
(flycheck-select-checker 'python-ruff)
(flycheck-add-next-checker 'python-ruff 'python-mypy)
))
(after! flycheck
(add-to-list 'flycheck-checkers 'python-ruff)
(add-hook 'python-mode-local-vars-hook #'python-flycheck-setup 'append)
) |
Thanks! |
Thank you for taking the time to improve Flycheck.
Checklist
Feature description
Add support for ruff (An extremely fast Python linter, written in Rust.).
The text was updated successfully, but these errors were encountered: