-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathflycheck-golangci-lint.el
115 lines (92 loc) · 4.41 KB
/
flycheck-golangci-lint.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;; flycheck-golangci-lint.el --- Flycheck checker for golangci-lint -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Wei Jian Gan
;; Author: Wei Jian Gan <weijiangan@outlook.com>
;; Keywords: convenience, tools, go
;; URL: https://github.com/weijiangan/flycheck-golangci-lint
;; Version: 0.1.0
;; Package-Requires: ((emacs "24") (flycheck "0.22"))
;; 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:
;; Flycheck checker for golangci-lint
;;
;; Usage:
;;
;; (eval-after-load 'flycheck
;; '(add-hook 'flycheck-mode-hook #'flycheck-golangci-lint-setup))
;;; Code:
(require 'flycheck)
(flycheck-def-option-var flycheck-golangci-lint-config nil golangci-lint
"Path to golangci-lint configuration file if you don't like using default config path .golangci.(yml|toml|json)"
:safe #'stringp)
(flycheck-def-option-var flycheck-golangci-lint-deadline "1m" golangci-lint
"Timeout for running golangci-lint, 1m by default."
:safe #'stringp)
(flycheck-def-option-var flycheck-golangci-lint-tests nil golangci-lint
"Analyze *_test.go files. It's false by default."
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-lint-fast nil golangci-lint
"Run only fast linters from the enabled set of linters. To find out which linters are fast run golangci-lint linters."
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-lint-disable-all nil golangci-lint
"Disable all linters"
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-lint-enable-all nil golangci-lint
"Enable all linters"
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-allow-parallel-runners nil golangci-lint
"Allow multiple parallel golangci-lint instances running"
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-allow-serial-runners nil golangci-lint
"Allow multiple golangci-lint instances running, but serialize them around a lock"
:safe #'booleanp
:type 'boolean)
(flycheck-def-option-var flycheck-golangci-lint-enable-linters nil golangci-lint
"Enable specific linters"
:type '(repeat (string :tag "linter"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-golangci-lint-disable-linters nil golangci-lint
"Disable specific linters"
:type '(repeat (string :tag "linter"))
:safe #'flycheck-string-list-p)
(flycheck-define-checker golangci-lint
"A Go syntax checker using golangci-lint that's 5x faster than gometalinter
See URL `https://github.com/golangci/golangci-lint'."
:command ("golangci-lint" "run" "--out-format=checkstyle"
(option "--config=" flycheck-golangci-lint-config concat)
(option "--timeout=" flycheck-golangci-lint-deadline concat)
(option-flag "--tests" flycheck-golangci-lint-tests)
(option-flag "--fast" flycheck-golangci-lint-fast)
(option-flag "--allow-parallel-runners" flycheck-golangci-allow-parallel-runners)
(option-flag "--allow-serial-runners" flycheck-golangci-allow-serial-runners)
(option-flag "--disable-all" flycheck-golangci-lint-disable-all)
(option-flag "--enable-all" flycheck-golangci-lint-enable-all)
(option-list "--disable=" flycheck-golangci-lint-disable-linters concat)
(option-list "--enable=" flycheck-golangci-lint-enable-linters concat)
".")
:error-parser flycheck-parse-checkstyle
:error-patterns
((error line-start (file-name) ":" line ":" column ": " (message) line-end)
(error line-start (file-name) ":" line ":" (message) line-end))
:modes go-mode)
;;;###autoload
(defun flycheck-golangci-lint-setup ()
"Setup Flycheck GolangCI-Lint.
Add `golangci-lint' to `flycheck-checkers'."
(interactive)
(add-to-list 'flycheck-checkers 'golangci-lint))
(provide 'flycheck-golangci-lint)
;;; flycheck-golangci-lint.el ends here