This repository was archived by the owner on Apr 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflycheck-typescript-tslint.el
130 lines (99 loc) · 4.07 KB
/
flycheck-typescript-tslint.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; flycheck-typescript-tslint.el --- Typescript tslint error checker
;; Copyright (C) 2015 Saša Jovanić
;; Author: Saša Jovanić <[email protected]>
;; URL: https://github.com/Simplify/flycheck-typescript-tslint/
;; Keywords: flycheck, Typescript, TSLint
;; Version: 0.40.0
;; Package-Version: 0.40.0
;; Package-Requires: ((flycheck "0.22") (emacs "24"))
;; 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:
;; This is extension for Flycheck.
;; This extension displays TSLint errors while working on Typescript project
;; TSLint:
;; https://github.com/palantir/tslint
;; Flycheck:
;; http://www.flycheck.org/
;; https://github.com/flycheck/flycheck
;; For more information about this Flycheck extension:
;; https://github.com/Simplify/flycheck-typescript-tslint
;;;; Setup
;; Install TSLint:
;; npm install -g tslint
;; npm install -g typescript
;;
;; Install flycheck-typescript-tslint using package.el.
;;
;; Add this into your init.el file:
;; (eval-after-load 'flycheck
;; '(add-hook 'flycheck-mode-hook #'flycheck-typescript-tslint-setup))
;;
;; Make sure to have tslint.conf in your project directory!
;;; Code:
(require 'flycheck)
(require 'json)
(flycheck-def-config-file-var flycheck-typescript-tslint-config typescript-tslint "tslint.json"
:safe #'stringp
:package-version '(flycheck . "0.22"))
(flycheck-def-option-var flycheck-typescript-tslint-rulesdir nil typescript-tslint
"The directory of custom rules for TSLint.
The value of this variable is either a string containing the path
to a directory with custom rules, or nil, to not give any custom
rules to TSLint.
Refer to the TSLint manual at URL
`http://palantir.github.io/tslint/usage/cli/'
for more information about the custom directory."
:type '(choice (const :tag "No custom rules directory" nil)
(directory :tag "Custom rules directory"))
:safe #'stringp)
(defun flycheck-parse-tslint (output checker buffer)
"Parse TSLint errors from JSON OUTPUT.
CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
the BUFFER that was checked respectively.
See URL `https://palantir.github.io/tslint/' for more information
about TSLint."
(let ((json-array-type 'list))
(let ((errors)
(tslint-json-output (json-read-from-string output)))
(dolist (emessage tslint-json-output)
(let-alist emessage
(push (flycheck-error-new-at
(+ 1 .startPosition.line)
(+ 1 .startPosition.character)
'warning .failure
:id .ruleName
:checker checker
:buffer buffer
:filename .name) errors)))
(nreverse errors))))
(flycheck-define-checker typescript-tslint
"Typescript tslint error checker.
See URL
`https://github.com/palantir/tslint'."
:command ("tslint"
"--format" "json"
(config-file "--config" flycheck-typescript-tslint-config)
(option "--rules-dir" flycheck-typescript-tslint-rulesdir)
source)
:error-parser flycheck-parse-tslint
:modes (typescript-mode))
(add-to-list 'flycheck-checkers 'typescript-tslint 'append)
;;;###autoload
(defun flycheck-typescript-tslint-setup ()
"Setup flycheck-typescript-tslint."
(interactive)
(add-to-list 'flycheck-checkers 'typescript-tslint 'append)
(if (bound-and-true-p tide-mode)
(flycheck-add-next-checker 'typescript-tide 'typescript-tslint 'append)))
(provide 'flycheck-typescript-tslint)
;;; flycheck-typescript-tslint.el ends here