From c820089c4434b621e8b30fbe73bbf9d01ee44f6f Mon Sep 17 00:00:00 2001 From: harttle Date: Tue, 26 Mar 2019 20:40:51 +0800 Subject: [PATCH 1/3] 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. --- ale_linters/css/fecs.vim | 12 ++++++ ale_linters/html/fecs.vim | 12 ++++++ ale_linters/javascript/fecs.vim | 10 +++++ autoload/ale/fix/registry.vim | 5 +++ autoload/ale/fixers/fecs.vim | 20 +++++++++ autoload/ale/handlers/fecs.vim | 52 +++++++++++++++++++++++ doc/ale-css.txt | 8 ++++ doc/ale-html.txt | 8 ++++ doc/ale-javascript.txt | 27 ++++++++++++ doc/ale-supported-languages-and-tools.txt | 3 ++ doc/ale.txt | 3 ++ supported-tools.md | 4 ++ test/handler/test_fecs_handler.vader | 35 +++++++++++++++ 13 files changed, 199 insertions(+) create mode 100644 ale_linters/css/fecs.vim create mode 100644 ale_linters/html/fecs.vim create mode 100644 ale_linters/javascript/fecs.vim create mode 100644 autoload/ale/fixers/fecs.vim create mode 100644 autoload/ale/handlers/fecs.vim create mode 100644 test/handler/test_fecs_handler.vader diff --git a/ale_linters/css/fecs.vim b/ale_linters/css/fecs.vim new file mode 100644 index 00000000..4b54d55a --- /dev/null +++ b/ale_linters/css/fecs.vim @@ -0,0 +1,12 @@ +" Author: harttle +" 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', +\}) diff --git a/ale_linters/html/fecs.vim b/ale_linters/html/fecs.vim new file mode 100644 index 00000000..5a49a6d8 --- /dev/null +++ b/ale_linters/html/fecs.vim @@ -0,0 +1,12 @@ +" Author: harttle +" 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', +\}) diff --git a/ale_linters/javascript/fecs.vim b/ale_linters/javascript/fecs.vim new file mode 100644 index 00000000..e47c0a0b --- /dev/null +++ b/ale_linters/javascript/fecs.vim @@ -0,0 +1,10 @@ +" Author: harttle +" 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', +\}) 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..c783588c --- /dev/null +++ b/autoload/ale/fixers/fecs.vim @@ -0,0 +1,20 @@ +" Author: harttle +" 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 diff --git a/autoload/ale/handlers/fecs.vim b/autoload/ale/handlers/fecs.vim new file mode 100644 index 00000000..ad94c61d --- /dev/null +++ b/autoload/ale/handlers/fecs.vim @@ -0,0 +1,52 @@ +" Author: harttle +" 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 + diff --git a/doc/ale-css.txt b/doc/ale-css.txt index f3cae385..a1e0ac5c 100644 --- a/doc/ale-css.txt +++ b/doc/ale-css.txt @@ -2,6 +2,14 @@ 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* diff --git a/doc/ale-html.txt b/doc/ale-html.txt index 1d30929f..5d6b20e2 100644 --- a/doc/ale-html.txt +++ b/doc/ale-html.txt @@ -2,6 +2,14 @@ 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* diff --git a/doc/ale-javascript.txt b/doc/ale-javascript.txt index 53a70fd7..ea0a7089 100644 --- a/doc/ale-javascript.txt +++ b/doc/ale-javascript.txt @@ -73,6 +73,33 @@ g:ale_javascript_eslint_suppress_missing_config 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* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index eff2e607..59115b81 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -187,6 +187,7 @@ Notes: * `terraform-fmt` * HTML * `alex`!! + * `fecs` * `HTMLHint` * `prettier` * `proselint` @@ -205,6 +206,7 @@ Notes: * `uncrustify` * JavaScript * `eslint` + * `fecs` * `flow` * `jscs` * `jshint` @@ -437,6 +439,7 @@ Notes: * `thrift` * TypeScript * `eslint` + * `fecs` * `prettier` * `tslint` * `tsserver` diff --git a/doc/ale.txt b/doc/ale.txt index 6d78fd89..f6ce9894 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1893,6 +1893,7 @@ documented in additional help files. mcsc..................................|ale-cs-mcsc| uncrustify............................|ale-cs-uncrustify| css.....................................|ale-css-options| + fecs..................................|ale-css-fecs| prettier..............................|ale-css-prettier| stylelint.............................|ale-css-stylelint| cuda....................................|ale-cuda-options| @@ -1970,6 +1971,7 @@ documented in additional help files. hcl.....................................|ale-hcl-options| terraform-fmt.........................|ale-hcl-terraform-fmt| html....................................|ale-html-options| + fecs..................................|ale-html-fecs| htmlhint..............................|ale-html-htmlhint| tidy..................................|ale-html-tidy| prettier..............................|ale-html-prettier| @@ -1988,6 +1990,7 @@ documented in additional help files. uncrustify............................|ale-java-uncrustify| javascript..............................|ale-javascript-options| eslint................................|ale-javascript-eslint| + fecs..................................|ale-javascript-fecs| flow..................................|ale-javascript-flow| importjs..............................|ale-javascript-importjs| jscs..................................|ale-javascript-jscs| diff --git a/supported-tools.md b/supported-tools.md index 74cea65c..c3eca442 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -98,6 +98,7 @@ formatting. * [crystal](https://crystal-lang.org/) :floppy_disk: * CSS * [csslint](http://csslint.net/) + * [fecs](http://fecs.baidu.com/) * [prettier](https://github.com/prettier/prettier) * [stylelint](https://github.com/stylelint/stylelint) * Cucumber @@ -196,6 +197,7 @@ formatting. * [terraform-fmt](https://github.com/hashicorp/terraform) * HTML * [alex](https://github.com/wooorm/alex) :floppy_disk: + * [fecs](http://fecs.baidu.com/) * [HTMLHint](http://htmlhint.com/) * [prettier](https://github.com/prettier/prettier) * [proselint](http://proselint.com/) @@ -214,6 +216,7 @@ formatting. * [uncrustify](https://github.com/uncrustify/uncrustify) * JavaScript * [eslint](http://eslint.org/) + * [fecs](http://fecs.baidu.com/) * [flow](https://flowtype.org/) * [jscs](http://jscs.info/) * [jshint](http://jshint.com/) @@ -446,6 +449,7 @@ formatting. * [thrift](http://thrift.apache.org/) * TypeScript * [eslint](http://eslint.org/) + * [fecs](http://fecs.baidu.com/) * [prettier](https://github.com/prettier/prettier) * [tslint](https://github.com/palantir/tslint) * [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29) diff --git a/test/handler/test_fecs_handler.vader b/test/handler/test_fecs_handler.vader new file mode 100644 index 00000000..7c216b8d --- /dev/null +++ b/test/handler/test_fecs_handler.vader @@ -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.', + \ ]) From d4841cedf22290a9746d220cd6682fac52262523 Mon Sep 17 00:00:00 2001 From: Jun Yang Date: Tue, 26 Mar 2019 23:39:45 +0800 Subject: [PATCH 2/3] style: fecs related doc and vim scripts --- ale_linters/css/fecs.vim | 3 --- ale_linters/html/fecs.vim | 3 --- autoload/ale/fixers/fecs.vim | 7 ++----- autoload/ale/handlers/fecs.vim | 4 ++-- doc/ale-css.txt | 8 ++++---- doc/ale-supported-languages-and-tools.txt | 1 + 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/ale_linters/css/fecs.vim b/ale_linters/css/fecs.vim index 4b54d55a..511847c6 100644 --- a/ale_linters/css/fecs.vim +++ b/ale_linters/css/fecs.vim @@ -1,9 +1,6 @@ " Author: harttle " 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'), diff --git a/ale_linters/html/fecs.vim b/ale_linters/html/fecs.vim index 5a49a6d8..15e00e12 100644 --- a/ale_linters/html/fecs.vim +++ b/ale_linters/html/fecs.vim @@ -1,9 +1,6 @@ " Author: harttle " 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'), diff --git a/autoload/ale/fixers/fecs.vim b/autoload/ale/fixers/fecs.vim index c783588c..d692bc97 100644 --- a/autoload/ale/fixers/fecs.vim +++ b/autoload/ale/fixers/fecs.vim @@ -1,9 +1,6 @@ " Author: harttle " 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) @@ -11,10 +8,10 @@ function! ale#fixers#fecs#Fix(buffer) abort return 0 endif - let l:config_options = ' format --replace=true' + let l:config_options = ' format --replace=true %t' return { - \ 'command': ale#Escape(l:executable) . l:config_options . ' %t', + \ '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 index ad94c61d..5362edb9 100644 --- a/autoload/ale/handlers/fecs.vim +++ b/autoload/ale/handlers/fecs.vim @@ -38,9 +38,9 @@ function! ale#handlers#fecs#Handle(buffer, lines) abort let l:obj.text = l:code_match[1] endif - if l:match[1] ==# 'WARN' + if l:match[1] is# 'WARN' let l:obj.type = 'W' - elseif l:match[1] ==# 'ERROR' + elseif l:match[1] is# 'ERROR' let l:obj.type = 'E' endif diff --git a/doc/ale-css.txt b/doc/ale-css.txt index a1e0ac5c..ff74b263 100644 --- a/doc/ale-css.txt +++ b/doc/ale-css.txt @@ -3,11 +3,11 @@ ALE CSS Integration *ale-css-options* =============================================================================== -fecs *ale-css-fecs* +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|. +`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|. =============================================================================== diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 59115b81..b870505f 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -89,6 +89,7 @@ Notes: * `crystal`!! * CSS * `csslint` + * `fecs` * `prettier` * `stylelint` * Cucumber From 4b6691f602e8574fb41b8e63d8d95f7c0ecbb878 Mon Sep 17 00:00:00 2001 From: harttle Date: Thu, 11 Apr 2019 19:47:31 +0800 Subject: [PATCH 3/3] test: unit test for fecs fixer, fecs command --- test/command_callback/fecs_paths/fecs | 0 test/command_callback/fecs_paths/fecs.exe | 0 .../test_fecs_command_callback.vader | 8 ++++++ test/fixers/test_fecs_fixer_callback.vader | 26 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100755 test/command_callback/fecs_paths/fecs create mode 100755 test/command_callback/fecs_paths/fecs.exe create mode 100644 test/command_callback/test_fecs_command_callback.vader create mode 100644 test/fixers/test_fecs_fixer_callback.vader diff --git a/test/command_callback/fecs_paths/fecs b/test/command_callback/fecs_paths/fecs new file mode 100755 index 00000000..e69de29b diff --git a/test/command_callback/fecs_paths/fecs.exe b/test/command_callback/fecs_paths/fecs.exe new file mode 100755 index 00000000..e69de29b diff --git a/test/command_callback/test_fecs_command_callback.vader b/test/command_callback/test_fecs_command_callback.vader new file mode 100644 index 00000000..f70ad084 --- /dev/null +++ b/test/command_callback/test_fecs_command_callback.vader @@ -0,0 +1,8 @@ +Before: + call ale#assert#SetUpLinterTest('javascript', 'fecs') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default command should be correct): + AssertLinter 'fecs', ale#Escape('fecs') . ' check --colors=false --rule=true %t' diff --git a/test/fixers/test_fecs_fixer_callback.vader b/test/fixers/test_fecs_fixer_callback.vader new file mode 100644 index 00000000..809b4d46 --- /dev/null +++ b/test/fixers/test_fecs_fixer_callback.vader @@ -0,0 +1,26 @@ +Before: + call ale#assert#SetUpFixerTest('javascript', 'fecs') + runtime autoload/ale/handlers/fecs.vim + +After: + call ale#assert#TearDownFixerTest() + +Execute(The fecs fixer should respect to g:ale_javascript_fecs_executable): + let g:ale_javascript_fecs_executable = 'fecs_paths/fecs' + let g:ale_javascript_fecs_use_global = 1 + silent cd ../command_callback + let g:dir = getcwd() + + AssertEqual + \ { + \ 'command': ale#Escape(g:ale_javascript_fecs_executable) . ' format --replace=true %t', + \ 'read_temporary_file': 1, + \ }, + \ ale#fixers#fecs#Fix(bufnr('')) + +Execute(The fecs fixer should return 0 when executable not found): + let g:ale_javascript_fecs_executable = 'fecs-invalid' + let g:ale_javascript_fecs_use_global = 1 + AssertEqual + \ 0, + \ ale#fixers#fecs#Fix(bufnr(''))