-
Notifications
You must be signed in to change notification settings - Fork 0
/
flycheck-ruff.el
66 lines (51 loc) · 2.17 KB
/
flycheck-ruff.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;; flycheck-ruff.el --- Flycheck syntax checker using ruff
;; Copyright © 2023, by https://github.com/mhvk
;; Author: mhvk <https://github.com/mhvk>
;; Maintainer: ed9w2in6
;; Version: 0.1
;; Package-Requires: ((flycheck "33-cvs"))
;; Created: 26 Oct 2023
;; Keywords: convenience, languages, tools
;; Homepage: None
;; This file is not part of GNU Emacs.
;;; License:
;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 2.
;;; Commentary:
;; Custom syntax checker for using ruff within flycheck
;; This is taken from: https://gist.github.com/abo-abo/277d1fe1e86f0e46d3161345f26e8f3a
;; It is indirectly from: https://github.com/flycheck/flycheck/issues/1974#issuecomment-1343495202
;;; Code:
(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))))))
(provide 'flycheck-ruff)
;;; flycheck-ruff.el ends here