diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index 9f4b43b7..cbab6fdd 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -357,6 +357,54 @@ function! syntastic#preprocess#stylelint(errors) abort " {{{2 return out 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 return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")') endfunction " }}}2 diff --git a/doc/syntastic-checkers.txt b/doc/syntastic-checkers.txt index 6fe190f7..b630c522 100644 --- a/doc/syntastic-checkers.txt +++ b/doc/syntastic-checkers.txt @@ -3009,6 +3009,7 @@ The following checkers are available for JavaScript (filetype "javascript"): 9. JSXHint..................|syntastic-javascript-jsxhint| 10. mixedindentlint.........|syntastic-javascript-mixedindentlint| 11. standard................|syntastic-javascript-standard| + 12. tern-lint...............|syntastic-javascript-tern_lint| ------------------------------------------------------------------------------ 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_generic = 1 < +------------------------------------------------------------------------------ +12. tern-lint *syntastic-javascript-tern_lint* + +Name: tern_lint +Maintainer: LCD 47 + +"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* diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 35eb60ac..a78412f9 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -19,7 +19,7 @@ if has('reltime') lockvar! g:_SYNTASTIC_START endif -let g:_SYNTASTIC_VERSION = '3.7.0-151' +let g:_SYNTASTIC_VERSION = '3.7.0-152' lockvar g:_SYNTASTIC_VERSION " Sanity checks {{{1 diff --git a/syntax_checkers/javascript/tern_lint.vim b/syntax_checkers/javascript/tern_lint.vim new file mode 100644 index 00000000..547942b0 --- /dev/null +++ b/syntax_checkers/javascript/tern_lint.vim @@ -0,0 +1,53 @@ +"============================================================================ +"File: tern_lint.vim +"Description: Syntax checking plugin for syntastic +"Maintainer: LCD 47 +"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: