-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflymake-relint.el
92 lines (74 loc) · 3.53 KB
/
flymake-relint.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; flymake-relint.el --- A relint Flymake backend -*- lexical-binding: t -*-
;; Copyright (C) 2023 liuyinz
;; Author: liuyinz <liuyinz95@gmail.com>
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1") (relint "1.23"))
;; Keywords: lisp
;; Homepage: https://github.com/liuyinz/flymake-relint
;; This file is not a part of GNU Emacsl.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Ported from https://github.com/purcell/flycheck-relint
;; Flymake is the built-in Emacs package to support on-the-fly syntax
;; checking. This library adds support for flymake to `relint'.
;; It requires Emacs 26.
;; Enable it by calling `flymake-relint-setup' from a
;; file-visiting buffer. To enable in all `emacs-lisp-mode' buffers:
;; (add-hook 'emacs-lisp-mode-hook #'flymake-relint-setup)
;;; Code:
(eval-when-compile
(require 'cl-lib))
(require 'flymake)
(require 'relint)
(declare-function flymake-diag-region "flymake")
(declare-function flymake-make-diagnostic "flymake")
(defun flymake-relint (report-fn &rest _args)
"A Flymake backend for `relint'.
Use `relint-flymake-setup' to add this to
`flymake-diagnostic-functions'. Calls REPORT-FN directly."
(let ((collection (relint-buffer (current-buffer))))
(cl-loop for (message expr-pos error-pos str str-idx severity) in
collection
collect
(let* ((pos (or error-pos expr-pos))
(msg (if error-pos
message
(mapconcat 'identity
(cons message
(when str
(cons (relint--quote-string str)
(when str-idx
(list (concat " " (relint--caret-string str str-idx)))))))
"\n")))
(region (save-excursion
(goto-char pos)
(move-beginning-of-line 1)
(flymake-diag-region (current-buffer)
(line-number-at-pos)
(- pos (point))))))
(flymake-make-diagnostic (current-buffer)
(car region)
(cdr region)
(if (eq severity 'warning) :warning :error)
msg))
into diags
finally (funcall report-fn diags))))
;;;###autoload
(defun flymake-relint-setup ()
"Setup relint integration with Flymake."
(interactive)
(if (< emacs-major-version 26)
(error "Package-lint-flymake requires Emacs 26 or later")
(add-hook 'flymake-diagnostic-functions #'flymake-relint nil t)
(flymake-mode)))
(provide 'flymake-relint)
;;; flymake-relint.el ends here