File: package-lint-flymake.el

package info (click to toggle)
package-lint-el 0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 244 kB
  • sloc: lisp: 2,527; sh: 30; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,696 bytes parent folder | download
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
;;; package-lint-flymake.el --- A package-lint Flymake backend  -*- lexical-binding: t; -*-

;; Copyright (C) 2018 J. Alexander Branham (alex DOT branham AT gmail DOT com)

;; Package-Requires: ((emacs "26") (package-lint "0.5"))
;; Homepage: https://github.com/purcell/package-lint

;; Version: 0.7

;; This file is not part of GNU Emacs.

;; This 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, or (at your option) any later
;; version.

;; This 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 GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
;; MA 02110-1301 USA.

;;; Commentary:

;; Flymake is the built-in Emacs package to support on-the-fly syntax
;; checking.  This library adds support for flymake to `package-lint'.
;; It requires Emacs 26.

;; Enable it by calling `package-lint-setup-flymake' from a
;; file-visiting buffer.  To enable in all `emacs-lisp-mode' buffers:
;;
;; (add-hook 'emacs-lisp-mode-hook #'package-lint-setup-flymake)

;;; Code:

(eval-when-compile
  (require 'cl-lib))
(require 'flymake)
(require 'package-lint)

(defvar-local package-lint--flymake-proc nil)

(declare-function flymake-diag-region "flymake")
(declare-function flymake-make-diagnostic "flymake")

(defun package-lint-flymake (report-fn &rest _args)
  "A Flymake backend for `package-lint'.
Use `package-lint-setup-flymake' to add this to
`flymake-diagnostic-functions'.  Calls REPORT-FN directly."
  (let ((collection (package-lint-buffer)))
    (cl-loop for (line col type message) in
             collection
             for (beg . end) = (flymake-diag-region (current-buffer) line col)
             collect
             (flymake-make-diagnostic
              (current-buffer)
              beg end
              (if (eq type 'warning) :warning :error)
              message)
             into diags
             finally (funcall report-fn diags))))

;;;###autoload
(defun package-lint-setup-flymake ()
  "Setup package-lint integration with Flymake."
  (if (< emacs-major-version 26)
      (error "Package-lint-flymake requires Emacs 26 or later")
    (add-hook 'flymake-diagnostic-functions #'package-lint-flymake nil t)
    (flymake-mode)))

(provide 'package-lint-flymake)

;;; package-lint-flymake.el ends here