Linter: tslint for typescript
This commit is contained in:
parent
60a03cb933
commit
de64c9d76f
@ -35,6 +35,7 @@ name. That seems to be the fairest way to arrange this table.
|
||||
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) |
|
||||
| Python | [flake8](http://flake8.pycqa.org/en/latest/) |
|
||||
| Ruby | [rubocop](https://github.com/bbatsov/rubocop) |
|
||||
| TypeScript | [tslint](https://github.com/palantir/tslint)^ |
|
||||
| Vim | [vint](https://github.com/Kuniwak/vint)^ |
|
||||
|
||||
*^ Supported only on Unix machines via a wrapper script.*
|
||||
|
51
ale_linters/typescript/tslint.vim
Normal file
51
ale_linters/typescript/tslint.vim
Normal file
@ -0,0 +1,51 @@
|
||||
" Author: Prashanth Chandra https://github.com/prashcr
|
||||
" Description: tslint for TypeScript files
|
||||
|
||||
if exists('g:loaded_ale_linters_typescript_tslint')
|
||||
finish
|
||||
endif
|
||||
|
||||
let g:loaded_ale_linters_typescript_tslint = 1
|
||||
|
||||
function! ale_linters#typescript#tslint#Handle(buffer, lines)
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" hello.ts[7, 41]: trailing whitespace
|
||||
" hello.ts[5, 1]: Forbidden 'var' keyword, use 'let' or 'const' instead
|
||||
"
|
||||
let pattern = '.\+.ts\[\(\d\+\), \(\d\+\)\]: \(.\+\)'
|
||||
let output = []
|
||||
|
||||
for line in a:lines
|
||||
let l:match = matchlist(line, pattern)
|
||||
|
||||
if len(l:match) == 0
|
||||
continue
|
||||
endif
|
||||
|
||||
let line = l:match[1] + 0
|
||||
let column = l:match[2] + 0
|
||||
let type = 'E'
|
||||
let text = l:match[3]
|
||||
|
||||
" vcol is Needed to indicate that the column is a character.
|
||||
call add(output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': line,
|
||||
\ 'vcol': 0,
|
||||
\ 'col': column,
|
||||
\ 'text': text,
|
||||
\ 'type': type,
|
||||
\ 'nr': -1,
|
||||
\})
|
||||
endfor
|
||||
|
||||
return output
|
||||
endfunction
|
||||
|
||||
call ALEAddLinter('typescript', {
|
||||
\ 'name': 'tslint',
|
||||
\ 'executable': 'tslint',
|
||||
\ 'command': g:ale#util#stdin_wrapper . ' .ts tslint',
|
||||
\ 'callback': 'ale_linters#typescript#tslint#Handle',
|
||||
\})
|
Loading…
Reference in New Issue
Block a user