Unverified Commit 9b8bf533 authored by Saša Jovanić's avatar Saša Jovanić Committed by Sebastian Wiesner

Add tslint checker for TypeScript

Closes GH-947 and closes GH-949
parent 985085d1
......@@ -9,6 +9,7 @@
- Go with ``go-unconvert`` [GH-905]
- Markdown with ``mdl`` [GH-839] [GH-916]
- TypeScript with ``tslint`` [GH-947] [GH-949]
- Improvements:
......@@ -42,6 +42,7 @@
(depends-on "scala-mode2")
(depends-on "scss-mode")
(depends-on "slim-mode")
(depends-on "typescript-mode")
(depends-on "web-mode")
(depends-on "yaml-mode")
......@@ -140,6 +140,7 @@ to Flycheck:
* Robert Dallas Gray (:gh:`rdallasgray`)
* Robert O'Connor (:gh:`robbyoconnor`)
* Robert Zaremba (:gh:`robert-zaremba`)
* Saša Jovanić (:gh:`Simplify`)
* Sean Gillespie (:gh:`swgillespie`)
* Sean Salmon (:gh:`phatcabbage`)
* Sebastian Beyer (:gh:`sebastianbeyer`)
......@@ -981,6 +981,24 @@ to view the docstring of the syntax checker. Likewise, you may use
.. _Texinfo: http://www.gnu.org/software/texinfo/
.. supported-language:: TypeScript
.. syntax-checker:: typescript-tslint
Check syntax and style with `TSLint <https://github.com/palantir/tslint>`_.
.. syntax-checker-config-file:: flycheck-typescript-tslint-config
.. important::
A configuration file is mandatory for this syntax checker. If
`flycheck-typescript-tslint-config` is not set or the configuration
file not found this syntax checker will not be used.
.. option:: flycheck-typescript-tslint-rulesdir
Additional rules directory, for user created rules.
.. supported-language:: Verilog
.. syntax-checker:: verilog-verilator
......@@ -84,6 +84,7 @@
(require 'rx) ; Regexp fanciness in `flycheck-define-checker'
(require 'help-mode) ; `define-button-type'
(require 'find-func) ; `find-function-regexp-alist'
(require 'json) ; `flycheck-parse-tslint'
;; Declare a bunch of dynamic variables that we need from other modes
......@@ -250,6 +251,7 @@ attention to case differences."
......@@ -5350,6 +5352,30 @@ See URL `http://phpmd.org/' for more information about phpmd."
(nreverse errors)))))
(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)
(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)
(nreverse errors)))
;;; Error parsing with regular expressions
(defun flycheck-get-regexp (patterns)
......@@ -8550,6 +8576,42 @@ See URL `http://www.gnu.org/software/texinfo/'."
:modes texinfo-mode)
(flycheck-def-config-file-var flycheck-typescript-tslint-config
typescript-tslint "tslint.json"
:safe #'stringp
:package-version '(flycheck . "27"))
(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
for more information about the custom directory."
:type '(choice (const :tag "No custom rules directory" nil)
(directory :tag "Custom rules directory"))
:safe #'stringp
:package-version '(flycheck . "27"))
(flycheck-define-checker typescript-tslint
"TypeScript style checker using TSLint.
Note that this syntax checker is not used if
`flycheck-typescript-tslint-config' is nil or refers to a
non-existing file.
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)
:error-parser flycheck-parse-tslint
:modes (typescript-mode))
(flycheck-def-option-var flycheck-verilator-include-path nil verilog-verilator
"A list of include directories for Verilator.
......@@ -4307,6 +4307,16 @@ Why not:
'(9 nil warning "printindex before document beginning: @printindex cp"
:checker texinfo)))
(flycheck-ert-def-checker-test typescript-tslint typescript nil
"language/typescript/sample.ts" 'typescript-mode
'(1 10 warning "unused variable: 'invalidAlignment'"
:checker typescript-tslint :id "no-unused-variable")
'(2 7 warning "unused variable: 'a'"
:checker typescript-tslint :id "no-unused-variable")
'(3 15 warning "missing semicolon"
:checker typescript-tslint :id "semicolon")))
(flycheck-ert-def-checker-test verilog-verilator verilog error
"language/verilog/verilator_error.v" 'verilog-mode
function invalidAlignment() {
let a:string = "test string";
\ No newline at end of file
"rules": {
"no-unused-variable": true,
"semicolon": true
;;; test-typescript.el --- Flycheck Specs: TypeScript -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors
;; Author: Saša Jovanić <info@simplify.ba>
;; 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
;; 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:
;; Specs for TypeScript support.
;;; Code:
(require 'flycheck-buttercup)
(defconst flycheck/typescript-lint-json
\"failure\":\"unused variable: 'invalidAlignment'\",
\"failure\":\"missing semicolon\",
(describe "Language TypeScript"
(describe "TSLint checker"
(it "parses TSLint JSON output"
(expect (flycheck-parse-tslint flycheck/typescript-lint-json
(flycheck-error-new-at 1 10 'warning
"unused variable: 'invalidAlignment'"
:id "no-unused-variable"
:checker 'checker
:buffer 'buffer
:filename "sample.ts")
(flycheck-error-new-at 3 15 'warning
"missing semicolon"
:id "semicolon"
:checker 'checker
:buffer 'buffer
:filename "sample.ts"))))))
;;; test-typescript.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment