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

12
ale_linters/css/fecs.vim Normal file
View File

@ -0,0 +1,12 @@
" Author: harttle <yangjvn@126.com>
" Description: fecs for CSS files
call ale#Set('css_fecs_executable', 'fecs')
call ale#Set('css_fecs_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#linter#Define('css', {
\ 'name': 'fecs',
\ 'executable': function('ale#handlers#fecs#GetExecutable'),
\ 'command': function('ale#handlers#fecs#GetCommand'),
\ 'callback': 'ale#handlers#fecs#Handle',
\})

12
ale_linters/html/fecs.vim Normal file
View File

@ -0,0 +1,12 @@
" Author: harttle <yangjvn@126.com>
" Description: fecs for HTMl files
call ale#Set('html_fecs_executable', 'fecs')
call ale#Set('html_fecs_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#linter#Define('html', {
\ 'name': 'fecs',
\ 'executable': function('ale#handlers#fecs#GetExecutable'),
\ 'command': function('ale#handlers#fecs#GetCommand'),
\ 'callback': 'ale#handlers#fecs#Handle',
\})

View File

@ -0,0 +1,10 @@
" Author: harttle <yangjvn@126.com>
" Description: fecs for JavaScript files
call ale#linter#Define('javascript', {
\ 'name': 'fecs',
\ 'executable': function('ale#handlers#fecs#GetExecutable'),
\ 'command': function('ale#handlers#fecs#GetCommand'),
\ 'read_buffer': 0,
\ 'callback': 'ale#handlers#fecs#Handle',
\})

View File

@ -27,6 +27,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'], \ 'suggested_filetypes': ['python'],
\ 'description': 'Fix PEP8 issues with black.', \ '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': { \ 'tidy': {
\ 'function': 'ale#fixers#tidy#Fix', \ 'function': 'ale#fixers#tidy#Fix',
\ 'suggested_filetypes': ['html'], \ '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

View File

@ -2,6 +2,14 @@
ALE CSS Integration *ale-css-options* ALE CSS Integration *ale-css-options*
===============================================================================
fecs *ale-css-fecs*
`fecs` options for CSS is the same as the options for JavaScript,
and both of them reads `./.fecsrc` as the default configuration file.
See: |ale-javascript-fecs|.
=============================================================================== ===============================================================================
prettier *ale-css-prettier* prettier *ale-css-prettier*

View File

@ -2,6 +2,14 @@
ALE HTML Integration *ale-html-options* ALE HTML Integration *ale-html-options*
===============================================================================
fecs *ale-html-fecs*
`fecs` options for HTMl is the same as the options for JavaScript,
and both of them reads `./.fecsrc` as the default configuration file.
See: |ale-javascript-fecs|.
=============================================================================== ===============================================================================
htmlhint *ale-html-htmlhint* htmlhint *ale-html-htmlhint*

View File

@ -73,6 +73,33 @@ g:ale_javascript_eslint_suppress_missing_config
configuration files are found. configuration files are found.
===============================================================================
fecs *ale-javascript-fecs*
`fecs` is a lint tool for HTML/CSS/JavaScript, can be installed via:
`$ npm install --save-dev fecs`
And the configuration file is located at `./fecsrc`, see http://fecs.baidu.com
for more options.
g:ale_javascript_fecs_executable *g:ale_javascript_fecs_executable*
*b:ale_javascript_fecs_executable*
Type: |String|
Default: `'fecs'`
See |ale-integrations-local-executables|
g:ale_javascript_fecs_use_global *g:ale_javascript_fecs_use_global*
*b:ale_javascript_fecs_use_global*
Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)`
See |ale-integrations-local-executables|
=============================================================================== ===============================================================================
flow *ale-javascript-flow* flow *ale-javascript-flow*

View File

@ -187,6 +187,7 @@ Notes:
* `terraform-fmt` * `terraform-fmt`
* HTML * HTML
* `alex`!! * `alex`!!
* `fecs`
* `HTMLHint` * `HTMLHint`
* `prettier` * `prettier`
* `proselint` * `proselint`
@ -205,6 +206,7 @@ Notes:
* `uncrustify` * `uncrustify`
* JavaScript * JavaScript
* `eslint` * `eslint`
* `fecs`
* `flow` * `flow`
* `jscs` * `jscs`
* `jshint` * `jshint`
@ -437,6 +439,7 @@ Notes:
* `thrift` * `thrift`
* TypeScript * TypeScript
* `eslint` * `eslint`
* `fecs`
* `prettier` * `prettier`
* `tslint` * `tslint`
* `tsserver` * `tsserver`

View File

@ -1893,6 +1893,7 @@ documented in additional help files.
mcsc..................................|ale-cs-mcsc| mcsc..................................|ale-cs-mcsc|
uncrustify............................|ale-cs-uncrustify| uncrustify............................|ale-cs-uncrustify|
css.....................................|ale-css-options| css.....................................|ale-css-options|
fecs..................................|ale-css-fecs|
prettier..............................|ale-css-prettier| prettier..............................|ale-css-prettier|
stylelint.............................|ale-css-stylelint| stylelint.............................|ale-css-stylelint|
cuda....................................|ale-cuda-options| cuda....................................|ale-cuda-options|
@ -1970,6 +1971,7 @@ documented in additional help files.
hcl.....................................|ale-hcl-options| hcl.....................................|ale-hcl-options|
terraform-fmt.........................|ale-hcl-terraform-fmt| terraform-fmt.........................|ale-hcl-terraform-fmt|
html....................................|ale-html-options| html....................................|ale-html-options|
fecs..................................|ale-html-fecs|
htmlhint..............................|ale-html-htmlhint| htmlhint..............................|ale-html-htmlhint|
tidy..................................|ale-html-tidy| tidy..................................|ale-html-tidy|
prettier..............................|ale-html-prettier| prettier..............................|ale-html-prettier|
@ -1988,6 +1990,7 @@ documented in additional help files.
uncrustify............................|ale-java-uncrustify| uncrustify............................|ale-java-uncrustify|
javascript..............................|ale-javascript-options| javascript..............................|ale-javascript-options|
eslint................................|ale-javascript-eslint| eslint................................|ale-javascript-eslint|
fecs..................................|ale-javascript-fecs|
flow..................................|ale-javascript-flow| flow..................................|ale-javascript-flow|
importjs..............................|ale-javascript-importjs| importjs..............................|ale-javascript-importjs|
jscs..................................|ale-javascript-jscs| jscs..................................|ale-javascript-jscs|

View File

@ -98,6 +98,7 @@ formatting.
* [crystal](https://crystal-lang.org/) :floppy_disk: * [crystal](https://crystal-lang.org/) :floppy_disk:
* CSS * CSS
* [csslint](http://csslint.net/) * [csslint](http://csslint.net/)
* [fecs](http://fecs.baidu.com/)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [stylelint](https://github.com/stylelint/stylelint) * [stylelint](https://github.com/stylelint/stylelint)
* Cucumber * Cucumber
@ -196,6 +197,7 @@ formatting.
* [terraform-fmt](https://github.com/hashicorp/terraform) * [terraform-fmt](https://github.com/hashicorp/terraform)
* HTML * HTML
* [alex](https://github.com/wooorm/alex) :floppy_disk: * [alex](https://github.com/wooorm/alex) :floppy_disk:
* [fecs](http://fecs.baidu.com/)
* [HTMLHint](http://htmlhint.com/) * [HTMLHint](http://htmlhint.com/)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [proselint](http://proselint.com/) * [proselint](http://proselint.com/)
@ -214,6 +216,7 @@ formatting.
* [uncrustify](https://github.com/uncrustify/uncrustify) * [uncrustify](https://github.com/uncrustify/uncrustify)
* JavaScript * JavaScript
* [eslint](http://eslint.org/) * [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/)
* [flow](https://flowtype.org/) * [flow](https://flowtype.org/)
* [jscs](http://jscs.info/) * [jscs](http://jscs.info/)
* [jshint](http://jshint.com/) * [jshint](http://jshint.com/)
@ -446,6 +449,7 @@ formatting.
* [thrift](http://thrift.apache.org/) * [thrift](http://thrift.apache.org/)
* TypeScript * TypeScript
* [eslint](http://eslint.org/) * [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [tslint](https://github.com/palantir/tslint) * [tslint](https://github.com/palantir/tslint)
* [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29) * [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29)

View File

@ -0,0 +1,35 @@
Before:
runtime autoload/ale/handlers/fecs.vim
After:
call ale#linter#Reset()
Execute(fecs should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 20,
\ 'col': 25,
\ 'text': 'Unexpected console statement.',
\ 'code': 'no-console',
\ 'type': 'W',
\ },
\ {
\ 'lnum': 24,
\ 'col': 36,
\ 'text': 'Missing radix parameter.',
\ 'code': 'radix',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 25,
\ 'col': 6,
\ 'text': 'Missing static property value.',
\ 'type': 'E',
\ },
\ ],
\ ale#handlers#fecs#Handle(347, [
\ 'fecs WARN → line 20, col 25: Unexpected console statement. (no-console)',
\ 'fecs ERROR → line 24, col 36: Missing radix parameter. (radix)',
\ 'fecs ERROR → line 25, col 6: Missing static property value.',
\ ])