New checker for JavaScript: tern-lint.
This commit is contained in:
parent
d6b96c079b
commit
5462fdd677
@ -357,6 +357,54 @@ function! syntastic#preprocess#stylelint(errors) abort " {{{2
|
|||||||
return out
|
return out
|
||||||
endfunction " }}}2
|
endfunction " }}}2
|
||||||
|
|
||||||
|
function! syntastic#preprocess#tern_lint(errors) abort " {{{2
|
||||||
|
let errs = join(a:errors, '')
|
||||||
|
let json = s:_decode_JSON(errs)
|
||||||
|
|
||||||
|
echomsg string(json)
|
||||||
|
let out = []
|
||||||
|
if type(json) == type({}) && has_key(json, 'messages') && type(json['messages']) == type([])
|
||||||
|
for e in json['messages']
|
||||||
|
try
|
||||||
|
let line_from = byte2line(e['from'] + 1)
|
||||||
|
if line_from > 0
|
||||||
|
let line = line_from
|
||||||
|
let column = e['from'] - line2byte(line_from) + 2
|
||||||
|
let line_to = byte2line(e['from'] + 1)
|
||||||
|
let hl = line_to == line ? e['to'] - line2byte(line_to) + 1 : 0
|
||||||
|
else
|
||||||
|
let line = 0
|
||||||
|
let column = 0
|
||||||
|
let hl = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if column < 0
|
||||||
|
let column = 0
|
||||||
|
endif
|
||||||
|
if hl < 0
|
||||||
|
let hl = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(out,
|
||||||
|
\ e['file'] . ':' .
|
||||||
|
\ e['severity'][0] . ':' .
|
||||||
|
\ line . ':' .
|
||||||
|
\ column . ':' .
|
||||||
|
\ hl . ':' .
|
||||||
|
\ e['message'])
|
||||||
|
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||||
|
call syntastic#log#warn('checker javascript/tern_lint: unrecognized error item ' . string(e))
|
||||||
|
let out = []
|
||||||
|
endtry
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
call syntastic#log#warn('checker javascript/tern_lint: unrecognized error format')
|
||||||
|
endif
|
||||||
|
|
||||||
|
echomsg string(out)
|
||||||
|
return out
|
||||||
|
endfunction " }}}2
|
||||||
|
|
||||||
function! syntastic#preprocess#tslint(errors) abort " {{{2
|
function! syntastic#preprocess#tslint(errors) abort " {{{2
|
||||||
return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")')
|
return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")')
|
||||||
endfunction " }}}2
|
endfunction " }}}2
|
||||||
|
@ -3009,6 +3009,7 @@ The following checkers are available for JavaScript (filetype "javascript"):
|
|||||||
9. JSXHint..................|syntastic-javascript-jsxhint|
|
9. JSXHint..................|syntastic-javascript-jsxhint|
|
||||||
10. mixedindentlint.........|syntastic-javascript-mixedindentlint|
|
10. mixedindentlint.........|syntastic-javascript-mixedindentlint|
|
||||||
11. standard................|syntastic-javascript-standard|
|
11. standard................|syntastic-javascript-standard|
|
||||||
|
12. tern-lint...............|syntastic-javascript-tern_lint|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
1. Closure Compiler *syntastic-javascript-closurecompiler*
|
1. Closure Compiler *syntastic-javascript-closurecompiler*
|
||||||
@ -3354,6 +3355,25 @@ example to use happiness (https://github.com/JedWatson/happiness) instead of
|
|||||||
let g:syntastic_javascript_standard_exec = "happiness"
|
let g:syntastic_javascript_standard_exec = "happiness"
|
||||||
let g:syntastic_javascript_standard_generic = 1
|
let g:syntastic_javascript_standard_generic = 1
|
||||||
<
|
<
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
12. tern-lint *syntastic-javascript-tern_lint*
|
||||||
|
|
||||||
|
Name: tern_lint
|
||||||
|
Maintainer: LCD 47 <lcd047@gmail.com>
|
||||||
|
|
||||||
|
"tern-lint" is a static type checker for JavaScript. See the project's page
|
||||||
|
for more information:
|
||||||
|
|
||||||
|
https://github.com/angelozerr/tern-lint
|
||||||
|
|
||||||
|
Syntastic requires a version of Vim compiled with the |+byte_offset| feature
|
||||||
|
to use this checker.
|
||||||
|
|
||||||
|
Checker options~
|
||||||
|
|
||||||
|
This checker is initialised using the "makeprgBuild()" function and thus it
|
||||||
|
accepts the standard options described at |syntastic-config-makeprg|.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
SYNTAX CHECKERS FOR JSON *syntastic-checkers-json*
|
SYNTAX CHECKERS FOR JSON *syntastic-checkers-json*
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ if has('reltime')
|
|||||||
lockvar! g:_SYNTASTIC_START
|
lockvar! g:_SYNTASTIC_START
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let g:_SYNTASTIC_VERSION = '3.7.0-151'
|
let g:_SYNTASTIC_VERSION = '3.7.0-152'
|
||||||
lockvar g:_SYNTASTIC_VERSION
|
lockvar g:_SYNTASTIC_VERSION
|
||||||
|
|
||||||
" Sanity checks {{{1
|
" Sanity checks {{{1
|
||||||
|
53
syntax_checkers/javascript/tern_lint.vim
Normal file
53
syntax_checkers/javascript/tern_lint.vim
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
"============================================================================
|
||||||
|
"File: tern_lint.vim
|
||||||
|
"Description: Syntax checking plugin for syntastic
|
||||||
|
"Maintainer: LCD 47 <lcd047@gmail.com>
|
||||||
|
"License: This program is free software. It comes without any warranty,
|
||||||
|
" to the extent permitted by applicable law. You can redistribute
|
||||||
|
" it and/or modify it under the terms of the Do What The Fuck You
|
||||||
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
||||||
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||||
|
"============================================================================
|
||||||
|
|
||||||
|
if exists('g:loaded_syntastic_javascript_tern_lint_checker')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let g:loaded_syntastic_javascript_tern_lint_checker = 1
|
||||||
|
|
||||||
|
let s:save_cpo = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
function! SyntaxCheckers_javascript_tern_lint_IsAvailable() dict
|
||||||
|
return has('byte_offset') && executable(self.getExec())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SyntaxCheckers_javascript_tern_lint_GetLocList() dict
|
||||||
|
let makeprg = self.makeprgBuild({})
|
||||||
|
|
||||||
|
let errorformat = '%f:%t:%l:%c:%n:%m'
|
||||||
|
|
||||||
|
let loclist = SyntasticMake({
|
||||||
|
\ 'makeprg': makeprg,
|
||||||
|
\ 'errorformat': errorformat,
|
||||||
|
\ 'preprocess': 'tern_lint',
|
||||||
|
\ 'returns': [0] })
|
||||||
|
|
||||||
|
for e in loclist
|
||||||
|
if get(e, 'col', 0) && get(e, 'nr', 0)
|
||||||
|
let e['hl'] = '\%>' . (e['col'] - 1) . 'c\%<' . (e['nr'] + 1) . 'c'
|
||||||
|
endif
|
||||||
|
let e['nr'] = 0
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return loclist
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||||
|
\ 'filetype': 'javascript',
|
||||||
|
\ 'name': 'tern_lint',
|
||||||
|
\ 'exec': 'tern-lint' })
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
" vim: set sw=4 sts=4 et fdm=marker:
|
Loading…
x
Reference in New Issue
Block a user