Skip to content

Instantly share code, notes, and snippets.

@dsedivec
Forked from abo-abo/flycheck-ruff.el
Last active February 22, 2025 15:20

Revisions

  1. dsedivec revised this gist Nov 24, 2023. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions flycheck-ruff.el
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,8 @@ 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"
    "check"
    "--output-format=text"
    (eval (when buffer-file-name
    (concat "--stdin-filename=" buffer-file-name)))
    "-")
    @@ -21,7 +22,7 @@ See URL `http://pypi.python.org/pypi/ruff'."
    (id (one-or-more (any alpha)) (one-or-more digit)) " "
    (message (one-or-more not-newline))
    line-end))
    :modes python-mode)
    :modes (python-mode python-ts-mode))

    ;; Use something adapted to your config to add `python-ruff' to `flycheck-checkers'
    ;; This is an MVP example:
  2. @abo-abo abo-abo created this gist Feb 20, 2023.
    33 changes: 33 additions & 0 deletions flycheck-ruff.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    (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))))))