blob: dcdef5c31ee84684885daef5a9fd7e8bcabd3fb1 (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
;;; flycheck-android-experimental.el --- Flycheck for Android using experimental
;;; gradle plugin
;; Copyright (C) 2017 by Joel Klinghed
;; Author: Joel Klinghed <the_jk@yahoo.com>
;;; Commentary:
;;; Code:
(require 'flycheck)
(defvar flycheck-android-sessiondir nil
"Session directory used for caching.")
(flycheck-def-option-var flycheck-android-java-checkstyle-jar nil android-java
"Path to checkstyle-VERSION-all.jar."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-checkstyle-jar)
(flycheck-def-option-var flycheck-android-java-checkstyle-path nil android-java
"Path to use as workdir and base for config and properties."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-checkstyle-path)
(flycheck-def-option-var flycheck-android-java-checkstyle-config nil android-java
"Path to checkstyle-config.xml if one should be used."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-checkstyle-config)
(flycheck-def-option-var flycheck-android-java-checkstyle-properties nil android-java
"Path to checkstyle.properties if one should be used."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-checkstyle-properties)
(flycheck-def-option-var flycheck-android-java-variant nil android-java
"Variant to select instead of first."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-variant)
(flycheck-def-option-var flycheck-android-kotlin-variant nil android-kotlin
"Variant to select instead of first."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-kotlin-variant)
(flycheck-def-option-var flycheck-android-java-skip-gen nil android-java
"Set to non-nil if generate*Sources task should not be run before checking."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-java-skip-gen)
(flycheck-def-option-var flycheck-android-kotlin-skip-gen nil android-kotlin
"Set to non-nil if generate*Sources task should not be run before checking."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-kotlin-skip-gen)
(flycheck-def-option-var flycheck-android-kotlin-detekt-cli nil android-kotlin
"Path to detekt-cli."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-kotlin-detekt-cli)
(flycheck-def-option-var flycheck-android-kotlin-detekt-config nil android-kotlin
"Path to detekt.yml."
:safe #'stringp)
(make-variable-buffer-local 'flycheck-android-kotlin-detekt-config)
(flycheck-define-checker android-java
"Java syntax checker using javac."
:command ("python"
(eval (flycheck-android-find-tool "java"))
(option "--checkstyle-jar="
flycheck-android-java-checkstyle-jar concat)
(option "--checkstyle-path="
flycheck-android-java-checkstyle-path concat)
(option "--checkstyle-config="
flycheck-android-java-checkstyle-config concat)
(option "--checkstyle-properties="
flycheck-android-java-checkstyle-properties concat)
(option "--variant="
flycheck-android-java-variant concat)
(option-flag "--skip-gen"
flycheck-android-java-skip-gen)
(eval (flycheck-android-get-sessiondir))
(eval buffer-file-name)
source)
:error-patterns
((warning line-start (file-name) ":" line ": warning:"
(message (one-or-more (not (any "^")))
(any "^"))
line-end)
(error line-start (file-name) ":" line ": error:"
(message (one-or-more (not (any "^")))
(any "^"))
line-end)
;; checkstyle messages (>= 7 style)
(warning line-start "[WARN] " (file-name) ":" line ":" column ": " (message) line-end)
(warning line-start "[WARN] " (file-name) ":" line ": " (message) line-end)
(error line-start "[ERROR] " (file-name) ":" line ":" column ": " (message) line-end)
(error line-start "[ERROR] " (file-name) ":" line ": " (message) line-end)
;; checkstyle messages (< 7 style)
(warning line-start (file-name) ":" line ": warning: " (message) line-end)
(error line-start (file-name) ":" line ":" column ": " (message) line-end)
(error line-start (file-name) ":" line ": " (message) line-end))
:modes java-mode)
(flycheck-define-checker android-kotlin
"Kotlin syntax checker using kotlin."
:command ("python"
(eval (flycheck-android-find-tool "kotlin"))
(option "--detekt-cli="
flycheck-android-kotlin-detekt-cli concat)
(option "--detekt-config="
flycheck-android-kotlin-detekt-config concat)
(option "--variant="
flycheck-android-kotlin-variant concat)
(option-flag "--skip-gen"
flycheck-android-kotlin-skip-gen)
(eval (flycheck-android-get-sessiondir))
(eval buffer-file-name)
source)
:error-patterns
((warning line-start (file-name) ":" line ":" column ": warning:"
(message (one-or-more (not (any "^")))
(any "^"))
line-end)
(error line-start (file-name) ":" line ":" column ": error:"
(message (one-or-more (not (any "^")))
(any "^"))
line-end)
;; detekt
(warning line-start (file-name) ":" line ":" column ": " (message) line-end))
:modes kotlin-mode)
(defun flycheck-android-find-tool (tool)
"Find flycheck-android-TOOL.py.
TOOL=name of tool"
(let ((filename (concat "flycheck-android-" tool ".py")))
(expand-file-name
filename
(concat (file-name-directory (symbol-file 'flycheck-android-find-tool))
(file-name-as-directory "bin")))))
(defun flycheck-android-remove-sessiondir ()
"Delete session dir if it exists and unsets the variable."
(when flycheck-android-sessiondir
(when (file-accessible-directory-p flycheck-android-sessiondir)
(delete-directory flycheck-android-sessiondir t))
(setq flycheck-android-sessiondir nil)))
(defun flycheck-android-get-sessiondir ()
"Return sessiondir if already set otherwise create and set it."
(or flycheck-android-sessiondir
(progn
(add-hook 'kill-emacs-hook 'flycheck-android-remove-sessiondir)
(setq flycheck-android-sessiondir
(make-temp-file "flycheck-android" t)))))
(add-to-list 'flycheck-checkers 'android-java)
(add-to-list 'flycheck-checkers 'android-kotlin)
(provide 'flycheck-android-experimental)
;;; flycheck-android-experimental.el ends here
|