feat: fecs support for js/html/css lint and format

`fecs` is a lint tool for HTML/CSS/JavaScript,
see http://fecs.baidu.com for more options.
This commit is contained in:
harttle
2019-03-26 20:40:51 +08:00
parent 4813165614
commit c820089c44
13 changed files with 199 additions and 0 deletions

View File

@@ -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'],

View File

@@ -0,0 +1,20 @@
" Author: harttle <yangjvn@126.com>
" Description: Apply fecs format to a file.
call ale#Set('html_fecs_executable', 'fecs')
call ale#Set('html_fecs_use_global', get(g:, 'ale_use_global_executables', 0))
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'
return {
\ 'command': ale#Escape(l:executable) . l:config_options . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@@ -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] ==# 'WARN'
let l:obj.type = 'W'
elseif l:match[1] ==# 'ERROR'
let l:obj.type = 'E'
endif
call add(l:output, l:obj)
endfor
return l:output
endfunction