Merge pull request #31 from prashcr/master

Linter: tslint for typescript
This commit is contained in:
w0rp 2016-10-03 22:27:52 +02:00 committed by GitHub
commit 66ee919756
2 changed files with 52 additions and 0 deletions

View File

@ -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.*

View 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',
\})