diff options
author | w0rp <w0rp@users.noreply.github.com> | 2019-04-13 12:35:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-13 12:35:52 +0100 |
commit | 784d1a9a622a0c30c26a17a835943593d036a4cd (patch) | |
tree | 0451624ea50fc92d6f8efbd9ef33484ccde2646f /autoload | |
parent | 6428162f792c4ed5905cc316b4099824c1af2fb2 (diff) | |
parent | 4b6691f602e8574fb41b8e63d8d95f7c0ecbb878 (diff) | |
download | ale-784d1a9a622a0c30c26a17a835943593d036a4cd.zip |
Merge pull request #2394 from harttle/master
feat: fecs support for js/html/css lint and format
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/fecs.vim | 17 | ||||
-rw-r--r-- | autoload/ale/handlers/fecs.vim | 52 |
3 files changed, 74 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 7118c44a..23d32f03 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -27,6 +27,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['python'], \ 'description': 'Fix PEP8 issues with black.', \ }, +\ 'fecs': { +\ 'function': 'ale#fixers#fecs#Fix', +\ 'suggested_filetypes': ['javascript', 'css', 'html'], +\ 'description': 'Apply fecs format to a file.', +\ }, \ 'tidy': { \ 'function': 'ale#fixers#tidy#Fix', \ 'suggested_filetypes': ['html'], diff --git a/autoload/ale/fixers/fecs.vim b/autoload/ale/fixers/fecs.vim new file mode 100644 index 00000000..d692bc97 --- /dev/null +++ b/autoload/ale/fixers/fecs.vim @@ -0,0 +1,17 @@ +" Author: harttle <yangjvn@126.com> +" Description: Apply fecs format to a file. + +function! ale#fixers#fecs#Fix(buffer) abort + let l:executable = ale#handlers#fecs#GetExecutable(a:buffer) + + if !executable(l:executable) + return 0 + endif + + let l:config_options = ' format --replace=true %t' + + return { + \ 'command': ale#Escape(l:executable) . l:config_options, + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/autoload/ale/handlers/fecs.vim b/autoload/ale/handlers/fecs.vim new file mode 100644 index 00000000..5362edb9 --- /dev/null +++ b/autoload/ale/handlers/fecs.vim @@ -0,0 +1,52 @@ +" Author: harttle <yangjvn@126.com> +" Description: fecs http://fecs.baidu.com/ + +call ale#Set('javascript_fecs_executable', 'fecs') +call ale#Set('javascript_fecs_use_global', get(g:, 'ale_use_global_executables', 0)) + +function! ale#handlers#fecs#GetCommand(buffer) abort + return '%e check --colors=false --rule=true %t' +endfunction + +function! ale#handlers#fecs#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'javascript_fecs', [ + \ 'node_modules/.bin/fecs', + \ 'node_modules/fecs/bin/fecs', + \]) +endfunction + +function! ale#handlers#fecs#Handle(buffer, lines) abort + " Matches patterns looking like the following + " + " fecs WARN → line 20, col 25: Unexpected console statement. (no-console) + " fecs ERROR → line 24, col 36: Missing radix parameter. (radix) + " + let l:pattern = '\v^.*(WARN|ERROR)\s+→\s+line (\d+),\s+col\s+(\d+):\s+(.*)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:obj = { + \ 'lnum': l:match[2] + 0, + \ 'col': l:match[3] + 0, + \ 'text': l:match[4] + \} + + let l:code_match = matchlist(l:match[4], '\v^(.{-})\s*\((.+)\)$') + + if !empty(l:code_match) + let l:obj.code = l:code_match[2] + let l:obj.text = l:code_match[1] + endif + + if l:match[1] is# 'WARN' + let l:obj.type = 'W' + elseif l:match[1] is# 'ERROR' + let l:obj.type = 'E' + endif + + call add(l:output, l:obj) + endfor + + return l:output +endfunction + |