-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflycheck-apex.el
92 lines (71 loc) · 2.75 KB
/
flycheck-apex.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
;;; flycheck-pmd.el --- Flycheck: PMD support -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Remy Goldschmidt <[email protected]>
;; Author: Remy Goldschmidt <[email protected]>
;; URL: https://github.com/taktoa/flycheck-pmd
;; Keywords: convenience, tools, languages
;; Version: 0.2-git
;; Package-Requires: ((emacs "24.1") (flycheck "0.22") (let-alist "1.0.3"))
;; This file is not part of GNU Emacs.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; PMD support for Flycheck.
;;; Code:
(eval-when-compile
(require 'let-alist)
(require 'cl))
(require 'flycheck)
(defun pair-fold1 (proc seed ls)
"Fold the procedure (PROC) with a seed (SEED) over a list (LS)."
(loop
for e on ls by #'cdr
for acc = (funcall proc ls seed)
then (funcall proc e acc)
finally (return acc)))
(defun single? (ls)
"Is the given list (LS) composed of a single element?"
(and (not (null ls))
(null (cdr ls))))
(defun intersperse (item ls)
"Intersperse an element (ITEM) in a list (LS)."
(pair-fold1 #'(lambda (pr acc)
(if (single? pr)
(cons (car pr) acc)
(cons item (cons (car pr) acc))))
'() (reverse ls)))
(defcustom
flycheck-pmd-rulesets
'("")
"List of rulesets for flycheck-pmd."
:group 'flycheck-options
:type '(repeat string))
(defconst
flycheck-pmd-args
(concat " -l java "
" -f emacs "
" -R " (apply 'concat (intersperse "," flycheck-pmd-rulesets)))
"Arguments for PMD error message.")
(defconst apex-ruleset "rulesets/apex/ruleset.xml")
(defconst pmd-dir "~/dev/pmd/pmd/bin/run.sh")
(flycheck-define-command-checker 'apex-pmd
"A syntax checker for Apex using PMD."
:command `(,pmd-dir "pmd" " -f " " emacs" " -R " ,apex-ruleset " -d " source )
;; :command `("pmd" "pmd" ,flycheck-pmd-args " -d " source)
:error-patterns '((error line-start (file-name) ":" line ": " (message) line-end))
:modes '(java-mode))
;;;###autoload
(defun flycheck-pmd-setup ()
"Setup Flycheck PMD.
Add `java-pmd' to `flycheck-checkers'."
(interactive)
(add-to-list 'flycheck-checkers 'apex-pmd))
(provide 'flycheck-pmd-apex)
;;; flycheck-pmd.el ends here