From c04603e1fd9051bf69b3af1daca9d6e4cabc0041 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Fri, 2 Nov 2018 18:14:47 +0200 Subject: [PATCH] New checker for JavaScript and TypeScript: lynt. --- autoload/syntastic/preprocess.vim | 38 +++++++++++++++++ doc/syntastic-checkers.txt | 64 +++++++++++++++++++++++++---- plugin/syntastic.vim | 2 +- syntax_checkers/javascript/lynt.vim | 49 ++++++++++++++++++++++ syntax_checkers/typescript/lynt.vim | 23 +++++++++++ 5 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 syntax_checkers/javascript/lynt.vim create mode 100644 syntax_checkers/typescript/lynt.vim diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index 1db577ed..e27acf10 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -251,6 +251,44 @@ function! syntastic#preprocess#killEmpty(errors) abort " {{{2 return filter(copy(a:errors), 'v:val !=# ""') endfunction " }}}2 +function! syntastic#preprocess#lynt(errors) abort " {{{2 + let errs = join(a:errors, '') + if errs ==# '' + return [] + endif + + let json = s:_decode_JSON(errs) + + let out = [] + if type(json) == type([]) + for err in json + if type(err) == type({}) && type(get(err, 'filePath')) == type('') && type(get(err, 'errors')) == type([]) + let fname = get(err, 'filePath') + + for e in get(err, 'errors') + if type(e) == type({}) + try + let line = e['line'] + let col = e['column'] + let ecol = line == get(e, 'endLine') ? get(e, 'endColumn') : 0 + let msg = e['message'] . ' [' . e['ruleName'] . ']' + + cal add(out, join([fname, line, col, ecol, msg], ':')) + catch /\m^Vim\%((\a\+)\)\=:E716/ + call syntastic#log#warn('checker javascript/lynt: unrecognized error item ' . string(e)) + endtry + else + call syntastic#log#warn('checker javascript/lynt unrecognized error item ' . string(e)) + endif + endfor + endif + endfor + else + call syntastic#log#warn('checker javascript/lynt unrecognized error format (crashed checker?)') + endif + return out +endfunction " }}}2 + function! syntastic#preprocess#perl(errors) abort " {{{2 let out = [] diff --git a/doc/syntastic-checkers.txt b/doc/syntastic-checkers.txt index 233ef651..f3639fa6 100644 --- a/doc/syntastic-checkers.txt +++ b/doc/syntastic-checkers.txt @@ -3408,9 +3408,10 @@ The following checkers are available for JavaScript (filetype "javascript"): 7. JSHint...................|syntastic-javascript-jshint| 8. JSLint...................|syntastic-javascript-jslint| 9. JSXHint..................|syntastic-javascript-jsxhint| - 10. mixedindentlint.........|syntastic-javascript-mixedindentlint| - 11. standard................|syntastic-javascript-standard| - 12. tern-lint...............|syntastic-javascript-tern_lint| + 10. Lynt....................|syntastic-javascript-lynt| + 11. mixedindentlint.........|syntastic-javascript-mixedindentlint| + 12. standard................|syntastic-javascript-standard| + 13. tern-lint...............|syntastic-javascript-tern_lint| ------------------------------------------------------------------------------ 1. Closure Compiler *syntastic-javascript-closurecompiler* @@ -3640,7 +3641,7 @@ syntastic to call "JSLint" with no options. ------------------------------------------------------------------------------ 9. JSXHint *syntastic-javascript-jsxhint* -Name: JSXHint +Name: jsxhint Maintainer: Thomas Boyt "JSXHint" is a wrapper around JSHint (http://jshint.com/) for @@ -3706,7 +3707,29 @@ To get around this, "Syntastic-React" can be used as a replacement for https://github.com/jaxbot/syntastic-react ------------------------------------------------------------------------------ -10. mixedindentlint *syntastic-javascript-mixedindentlint* +10. Lynt *syntastic-javascript-lynt* + +Name: lynt +Maintainer: LCD 47 + +"Lynt" is a JavaScript linter with support for TypeScript, Flow, and React. +See the project's page for more information: + + https://github.com/saadq/lynt + +Checker options~ + +This checker is initialised using the "makeprgBuild()" function and thus it +accepts the standard options described at |syntastic-config-makeprg|. + +Note~ + +Automatically fixing errors (option "--fix") is not supported. + +See also: |syntastic-typescript-lynt|. + +------------------------------------------------------------------------------ +11. mixedindentlint *syntastic-javascript-mixedindentlint* Name: mixedindentlint Maintainer: Payton Swick @@ -3724,7 +3747,7 @@ accepts the standard options described at |syntastic-config-makeprg|. See also: |syntastic-css-mixedindentlint|, |syntastic-scss-mixedindentlint|. ------------------------------------------------------------------------------ -11. standard *syntastic-javascript-standard* +12. standard *syntastic-javascript-standard* Name: standard Maintainer: LCD 47 @@ -3758,7 +3781,7 @@ example to use happiness (https://github.com/JedWatson/happiness) instead of let g:syntastic_javascript_standard_generic = 1 < ------------------------------------------------------------------------------ -12. tern-lint *syntastic-javascript-tern_lint* +13. tern-lint *syntastic-javascript-tern_lint* Name: tern_lint Maintainer: LCD 47 @@ -6913,7 +6936,8 @@ SYNTAX CHECKERS FOR TYPESCRIPT *syntastic-checkers-typescript* The following checkers are available for TypeScript (filetype "typescript"): 1. ESLint...................|syntastic-typescript-eslint| - 2. TSLint...................|syntastic-typescript-tslint| + 2. Lynt.....................|syntastic-typescript-lynt| + 3. TSLint...................|syntastic-typescript-tslint| ------------------------------------------------------------------------------ 1. ESLint *syntastic-typescript-eslint* @@ -6944,7 +6968,29 @@ See also: |syntastic-html-eslint|, |syntastic-javascript-eslint|, |syntastic-vue-eslint|. ------------------------------------------------------------------------------ -2. TSLint *syntastic-typescript-tslint* +2. Lynt *syntastic-typescript-lynt* + +Name: lynt +Maintainer: LCD 47 + +"Lynt" is a JavaScript linter with support for TypeScript, Flow, and React. +See the project's page for more information: + + https://github.com/saadq/lynt + +Checker options~ + +This checker is initialised using the "makeprgBuild()" function and thus it +accepts the standard options described at |syntastic-config-makeprg|. + +Note~ + +Automatically fixing errors (option "--fix") is not supported. + +See also: |syntastic-javascript-lynt|. + +------------------------------------------------------------------------------ +3. TSLint *syntastic-typescript-tslint* Name: tslint Maintainer: Seon-Wook Park diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 78cce925..dc02404b 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.9.0-19' +let g:_SYNTASTIC_VERSION = '3.9.0-20' lockvar g:_SYNTASTIC_VERSION " Sanity checks {{{1 diff --git a/syntax_checkers/javascript/lynt.vim b/syntax_checkers/javascript/lynt.vim new file mode 100644 index 00000000..a55d2fa4 --- /dev/null +++ b/syntax_checkers/javascript/lynt.vim @@ -0,0 +1,49 @@ +"============================================================================ +"File: lynt.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_lynt_checker') + finish +endif +let g:loaded_syntastic_javascript_lynt_checker = 1 + +let s:save_cpo = &cpo +set cpo&vim + +function! SyntaxCheckers_javascript_lynt_GetLocList() dict + let makeprg = self.makeprgBuild({ 'args_after': '--json' }) + + let errorformat = '%f:%l:%c:%n:%m' + + let loclist = SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'preprocess': 'lynt', + \ 'defaults': {'type': 'E'}, + \ 'returns': [0, 1] }) + + for e in loclist + if get(e, 'col', 0) && get(e, 'nr', 0) + let e['hl'] = '\%>' . (e['col'] - 1) . 'c\%<' . (e['nr']) . 'c' + let e['nr'] = 0 + endif + endfor + + return loclist +endfunction + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'javascript', + \ 'name': 'lynt'}) + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/syntax_checkers/typescript/lynt.vim b/syntax_checkers/typescript/lynt.vim new file mode 100644 index 00000000..3d84db4f --- /dev/null +++ b/syntax_checkers/typescript/lynt.vim @@ -0,0 +1,23 @@ +"============================================================================ +"File: lynt.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_typescript_lynt_checker') + finish +endif +let g:loaded_syntastic_typescript_lynt_checker = 1 + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'typescript', + \ 'name': 'lynt', + \ 'redirect': 'javascript/lynt'}) + +" vim: set sw=4 sts=4 et fdm=marker: