From a1e6df987c28dd3e0efb7422f4ad85ee3bb3bebc Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Fri, 22 Jan 2021 18:27:36 +0900 Subject: Fix 354 - Migrate CI from travis to Github Actions (#3549) * Fix 354 - Migrate CI from travis to Github Actions * Use matrix strategy for parallel tests * Don't build image on each run * Add push trigger on tags Co-authored-by: Horacio Sanson --- .github/workflows/main.yml | 23 +++++++++++++++++++++++ .travis.yml | 16 ---------------- 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..7c182758 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: CI +on: + push: + branches: [ master ] + tags: + - /^v\d+\.\d+\.(x|\d+)$/ + pull_request: + branches: [ master ] + +jobs: + test_ale: + runs-on: ubuntu-latest + strategy: + matrix: + vim-version: + - '--vim-80-only' + - '--vim-81-only' + - '--neovim-only' + - '--linters-only' + steps: + - uses: actions/checkout@v2 + - name: Run tests + run: ./run-tests -v ${{ matrix.vim-version }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 00baff1c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -sudo: required -services: - - docker -language: generic -branches: - only: - - master - - /^v\d+\.\d+\.(x|\d+)$/ -env: - - OPTIONS=--vim-80-only - - OPTIONS=--vim-81-only - - OPTIONS=--neovim-only - - OPTIONS=--linters-only -script: | - ./run-tests -v $OPTIONS -- cgit v1.2.3 From 03eae9e085f6020a017ecbe761cccac9a5a89d77 Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Fri, 20 Sep 2019 22:04:44 +0900 Subject: Fix 2777 - Add IBM openapi validator --- ale_linters/openapi/ibm_validator.vim | 58 ++++++++++++++++++++++ doc/ale-openapi.txt | 42 ++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 2 + doc/ale.txt | 2 + supported-tools.md | 2 + ...st_ibm_openapi_validator_command_callback.vader | 15 ++++++ .../test_ibm_openapi_validator_handler.vader | 49 ++++++++++++++++++ 7 files changed, 170 insertions(+) create mode 100644 ale_linters/openapi/ibm_validator.vim create mode 100644 doc/ale-openapi.txt create mode 100644 test/command_callback/test_ibm_openapi_validator_command_callback.vader create mode 100644 test/handler/test_ibm_openapi_validator_handler.vader diff --git a/ale_linters/openapi/ibm_validator.vim b/ale_linters/openapi/ibm_validator.vim new file mode 100644 index 00000000..c54741d2 --- /dev/null +++ b/ale_linters/openapi/ibm_validator.vim @@ -0,0 +1,58 @@ +" Author: Horacio Sanson + +call ale#Set('openapi_ibm_validator_executable', 'lint-openapi') +call ale#Set('openapi_ibm_validator_options', '') + +function! ale_linters#openapi#ibm_validator#GetCommand(buffer) abort + return '%e' . ale#Pad(ale#Var(a:buffer, 'openapi_ibm_validator_options')) + \ . ' %t' +endfunction + +function! ale_linters#openapi#ibm_validator#Handle(buffer, lines) abort + let l:output = [] + let l:type = 'E' + let l:message = '' + let l:nr = -1 + + for l:line in a:lines + let l:match = matchlist(l:line, '^errors$') + + if !empty(l:match) + let l:type = 'E' + endif + + let l:match = matchlist(l:line, '^warnings$') + + if !empty(l:match) + let l:type = 'W' + endif + + let l:match = matchlist(l:line, '^ *Message : *\(.\+\)$') + + if !empty(l:match) + let l:message = l:match[1] + endif + + let l:match = matchlist(l:line, '^ *Line *: *\(\d\+\)$') + + if !empty(l:match) + let l:nr = l:match[1] + + call add(l:output, { + \ 'lnum': l:nr + 0, + \ 'col': 0, + \ 'text': l:message, + \ 'type': l:type, + \}) + endif + endfor + + return l:output +endfunction + +call ale#linter#Define('openapi', { +\ 'name': 'ibm-validator', +\ 'executable': {b -> ale#Var(b, 'openapi_ibm_validator_executable')}, +\ 'command': function('ale_linters#openapi#ibm_validator#GetCommand'), +\ 'callback': 'ale_linters#openapi#ibm_validator#Handle', +\}) diff --git a/doc/ale-openapi.txt b/doc/ale-openapi.txt new file mode 100644 index 00000000..d0ab9bfc --- /dev/null +++ b/doc/ale-openapi.txt @@ -0,0 +1,42 @@ +=============================================================================== +ALE OpenApi Integration *ale-openapi-options* + +=============================================================================== +ibm-validator *ale-openapi-ibm-validator* + +Website: https://github.com/IBM/openapi-validator + + +Installation +------------------------------------------------------------------------------- + +Install ibm-openapi-validator either globally or locally: > + + npm install ibm-openapi-validator -g # global + npm install ibm-openapi-validator # local +< +Recommended plugin for openapi filetype detection: + + https://github.com/hsanson/vim-openapi + +Options +------------------------------------------------------------------------------- + +g:ale_openapi_ibm_validator_executable *g:ale_openapi_ibm_validator_executable* + *b:ale_openapi_ibm_validator_executable* + Type: |String| + Default: `'lint-openapi'` + + This variable can be set to change the path to lint-openapi. + + +g:ale_openapi_ibm_validator_options *g:ale_openapi_ibm_validator_options* + *b:ale_openapi_ibm_validator_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to lint-openapi. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 5476be47..b73bec4f 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -322,6 +322,8 @@ Notes: * `ocamlformat` * `ocp-indent` * `ols` +* OpenApi + * `ibm-validator` * Pawn * `uncrustify` * Perl diff --git a/doc/ale.txt b/doc/ale.txt index 721ca69d..68ac8498 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2835,6 +2835,8 @@ documented in additional help files. ols...................................|ale-ocaml-ols| ocamlformat...........................|ale-ocaml-ocamlformat| ocp-indent............................|ale-ocaml-ocp-indent| + openapi.................................|ale-openapi-options| + ibm-validator.........................|ale-openapi-ibm-validator| pawn....................................|ale-pawn-options| uncrustify............................|ale-pawn-uncrustify| perl....................................|ale-perl-options| diff --git a/supported-tools.md b/supported-tools.md index b07f6acf..a74fdd99 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -331,6 +331,8 @@ formatting. * [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) * [ocp-indent](https://github.com/OCamlPro/ocp-indent) * [ols](https://github.com/freebroccolo/ocaml-language-server) +* OpenApi + * [ibm-validator](https://github.com/IBM/openapi-validator) * Pawn * [uncrustify](https://github.com/uncrustify/uncrustify) * Perl diff --git a/test/command_callback/test_ibm_openapi_validator_command_callback.vader b/test/command_callback/test_ibm_openapi_validator_command_callback.vader new file mode 100644 index 00000000..3484cc09 --- /dev/null +++ b/test/command_callback/test_ibm_openapi_validator_command_callback.vader @@ -0,0 +1,15 @@ +Before: + call ale#assert#SetUpLinterTest('openapi', 'ibm_validator') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The yaml ibm-openapi-validator command callback should return the correct default string): + AssertLinter 'lint-openapi', ale#Escape('lint-openapi') . ' %t' + +Execute(The yaml ibm-openapi-validator command callback should be configurable): + let g:ale_openapi_ibm_validator_executable = '~/.local/bin/lint-openapi' + let g:ale_openapi_ibm_validator_options = '-c ~/.config' + + AssertLinter '~/.local/bin/lint-openapi', ale#Escape('~/.local/bin/lint-openapi') + \ . ' -c ~/.config %t' diff --git a/test/handler/test_ibm_openapi_validator_handler.vader b/test/handler/test_ibm_openapi_validator_handler.vader new file mode 100644 index 00000000..e136d5d2 --- /dev/null +++ b/test/handler/test_ibm_openapi_validator_handler.vader @@ -0,0 +1,49 @@ +Before: + runtime! ale_linters/openapi/ibm_validator.vim + +After: + call ale#linter#Reset() + +Execute(Problems should be parsed correctly for openapi-ibm-validator): + AssertEqual + \ [ + \ { + \ 'lnum': 54, + \ 'col': 0, + \ 'type': 'E', + \ 'text': 'Items with a description must have content in it.', + \ }, + \ { + \ 'lnum': 24, + \ 'col': 0, + \ 'type': 'W', + \ 'text': 'Operations must have a non-empty `operationId`.', + \ }, + \ { + \ 'lnum': 40, + \ 'col': 0, + \ 'type': 'W', + \ 'text': 'operationIds must follow case convention: lower_snake_case', + \ }, + \ ], + \ ale_linters#openapi#ibm_validator#Handle(bufnr(''), [ + \ '', + \ '[Warning] No .validaterc file found. The validator will run in default mode.', + \ 'To configure the validator, create a .validaterc file.', + \ '', + \ 'errors', + \ '', + \ ' Message : Items with a description must have content in it.', + \ ' Path : paths./settings.patch.description', + \ ' Line : 54', + \ '', + \ 'warnings', + \ '', + \ ' Message : Operations must have a non-empty `operationId`.', + \ ' Path : paths./stats.get.operationId', + \ ' Line : 24', + \ '', + \ ' Message : operationIds must follow case convention: lower_snake_case', + \ ' Path : paths./settings.get.operationId', + \ ' Line : 40' + \ ]) -- cgit v1.2.3 From 014b00d4d778bbfe027e927183b44ce3424679b4 Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Sun, 27 Oct 2019 00:16:23 +0900 Subject: Add yamllint and prettier to openapi. This commit enables yamllint and prettier on openapi files. --- ale_linters/openapi/yamllint.vim | 9 +++++++ ale_linters/yaml/yamllint.vim | 43 ++----------------------------- autoload/ale/fix/registry.vim | 2 +- autoload/ale/fixers/prettier.vim | 1 + autoload/ale/handlers/yamllint.vim | 39 ++++++++++++++++++++++++++++ doc/ale-openapi.txt | 12 +++++++++ doc/ale-supported-languages-and-tools.txt | 2 ++ doc/ale.txt | 2 ++ supported-tools.md | 2 ++ test/handler/test_yamllint_handler.vader | 8 +++--- 10 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 ale_linters/openapi/yamllint.vim create mode 100644 autoload/ale/handlers/yamllint.vim diff --git a/ale_linters/openapi/yamllint.vim b/ale_linters/openapi/yamllint.vim new file mode 100644 index 00000000..2b8952cc --- /dev/null +++ b/ale_linters/openapi/yamllint.vim @@ -0,0 +1,9 @@ +call ale#Set('yaml_yamllint_executable', 'yamllint') +call ale#Set('yaml_yamllint_options', '') + +call ale#linter#Define('openapi', { +\ 'name': 'yamllint', +\ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')}, +\ 'command': function('ale#handlers#yamllint#GetCommand'), +\ 'callback': 'ale#handlers#yamllint#Handle', +\}) diff --git a/ale_linters/yaml/yamllint.vim b/ale_linters/yaml/yamllint.vim index bedb7bf1..39011df1 100644 --- a/ale_linters/yaml/yamllint.vim +++ b/ale_linters/yaml/yamllint.vim @@ -3,48 +3,9 @@ call ale#Set('yaml_yamllint_executable', 'yamllint') call ale#Set('yaml_yamllint_options', '') -function! ale_linters#yaml#yamllint#GetCommand(buffer) abort - return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_yamllint_options')) - \ . ' -f parsable %t' -endfunction - -function! ale_linters#yaml#yamllint#Handle(buffer, lines) abort - " Matches patterns line the following: - " something.yaml:1:1: [warning] missing document start "---" (document-start) - " something.yml:2:1: [error] syntax error: expected the node content, but found '' - let l:pattern = '\v^.*:(\d+):(\d+): \[(error|warning)\] (.+)$' - let l:output = [] - - for l:match in ale#util#GetMatches(a:lines, l:pattern) - let l:item = { - \ 'lnum': l:match[1] + 0, - \ 'col': l:match[2] + 0, - \ 'text': l:match[4], - \ 'type': l:match[3] is# 'error' ? 'E' : 'W', - \} - - let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^)]+)\)$') - - if !empty(l:code_match) - if l:code_match[2] is# 'trailing-spaces' - \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace') - " Skip warnings for trailing whitespace if the option is off. - continue - endif - - let l:item.text = l:code_match[1] - let l:item.code = l:code_match[2] - endif - - call add(l:output, l:item) - endfor - - return l:output -endfunction - call ale#linter#Define('yaml', { \ 'name': 'yamllint', \ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')}, -\ 'command': function('ale_linters#yaml#yamllint#GetCommand'), -\ 'callback': 'ale_linters#yaml#yamllint#Handle', +\ 'command': function('ale#handlers#yamllint#GetCommand'), +\ 'callback': 'ale#handlers#yamllint#Handle', \}) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index f514466e..4564954b 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -102,7 +102,7 @@ let s:default_registry = { \ }, \ 'prettier': { \ 'function': 'ale#fixers#prettier#Fix', -\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'html', 'yaml'], +\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'html', 'yaml', 'openapi'], \ 'description': 'Apply prettier to a file.', \ }, \ 'prettier_eslint': { diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim index e0f4972e..12c018af 100644 --- a/autoload/ale/fixers/prettier.vim +++ b/autoload/ale/fixers/prettier.vim @@ -83,6 +83,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort \ 'markdown': 'markdown', \ 'vue': 'vue', \ 'yaml': 'yaml', + \ 'openapi': 'yaml', \ 'html': 'html', \} diff --git a/autoload/ale/handlers/yamllint.vim b/autoload/ale/handlers/yamllint.vim new file mode 100644 index 00000000..5e04577d --- /dev/null +++ b/autoload/ale/handlers/yamllint.vim @@ -0,0 +1,39 @@ +function! ale#handlers#yamllint#GetCommand(buffer) abort + return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_yamllint_options')) + \ . ' -f parsable %t' +endfunction + +function! ale#handlers#yamllint#Handle(buffer, lines) abort + " Matches patterns line the following: + " something.yaml:1:1: [warning] missing document start "---" (document-start) + " something.yml:2:1: [error] syntax error: expected the node content, but found '' + let l:pattern = '\v^.*:(\d+):(\d+): \[(error|warning)\] (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:item = { + \ 'lnum': l:match[1] + 0, + \ 'col': l:match[2] + 0, + \ 'text': l:match[4], + \ 'type': l:match[3] is# 'error' ? 'E' : 'W', + \} + + let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^)]+)\)$') + + if !empty(l:code_match) + if l:code_match[2] is# 'trailing-spaces' + \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace') + " Skip warnings for trailing whitespace if the option is off. + continue + endif + + let l:item.text = l:code_match[1] + let l:item.code = l:code_match[2] + endif + + call add(l:output, l:item) + endfor + + return l:output +endfunction + diff --git a/doc/ale-openapi.txt b/doc/ale-openapi.txt index d0ab9bfc..27261de6 100644 --- a/doc/ale-openapi.txt +++ b/doc/ale-openapi.txt @@ -38,5 +38,17 @@ g:ale_openapi_ibm_validator_options *g:ale_openapi_ibm_validator_options* This variable can be set to pass additional options to lint-openapi. +=============================================================================== +prettier *ale-openapi-prettier* + +See |ale-javascript-prettier| for information about the available options. + + +=============================================================================== +yamllint *ale-openapi-yamllint* + +See |ale-yaml-yamllint| for information about the available options. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index b73bec4f..57eb71dc 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -324,6 +324,8 @@ Notes: * `ols` * OpenApi * `ibm-validator` + * `prettier` + * `yamllint` * Pawn * `uncrustify` * Perl diff --git a/doc/ale.txt b/doc/ale.txt index 68ac8498..b2cea4cd 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2837,6 +2837,8 @@ documented in additional help files. ocp-indent............................|ale-ocaml-ocp-indent| openapi.................................|ale-openapi-options| ibm-validator.........................|ale-openapi-ibm-validator| + prettier..............................|ale-openapi-prettier| + yamllint..............................|ale-openapi-yamllint| pawn....................................|ale-pawn-options| uncrustify............................|ale-pawn-uncrustify| perl....................................|ale-perl-options| diff --git a/supported-tools.md b/supported-tools.md index a74fdd99..df9071f8 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -333,6 +333,8 @@ formatting. * [ols](https://github.com/freebroccolo/ocaml-language-server) * OpenApi * [ibm-validator](https://github.com/IBM/openapi-validator) + * [prettier](https://github.com/prettier/prettier) + * [yamllint](https://yamllint.readthedocs.io/) * Pawn * [uncrustify](https://github.com/uncrustify/uncrustify) * Perl diff --git a/test/handler/test_yamllint_handler.vader b/test/handler/test_yamllint_handler.vader index 1aa0b9f5..dd51119c 100644 --- a/test/handler/test_yamllint_handler.vader +++ b/test/handler/test_yamllint_handler.vader @@ -3,7 +3,7 @@ Before: let g:ale_warn_about_trailing_whitespace = 1 - runtime! ale_linters/yaml/yamllint.vim + runtime! ale/handlers/yamllint.vim After: Restore @@ -29,7 +29,7 @@ Execute(Problems should be parsed correctly for yamllint): \ 'text': 'syntax error: expected the node content, but found ''''', \ }, \ ], - \ ale_linters#yaml#yamllint#Handle(bufnr(''), [ + \ ale#handlers#yamllint#Handle(bufnr(''), [ \ 'something.yaml:1:1: [warning] missing document start "---" (document-start)', \ 'something.yml:2:1: [error] syntax error: expected the node content, but found ''''', \ ]) @@ -45,7 +45,7 @@ Execute(The yamllint handler should respect ale_warn_about_trailing_whitespace): \ 'code': 'trailing-spaces', \ }, \ ], - \ ale_linters#yaml#yamllint#Handle(bufnr(''), [ + \ ale#handlers#yamllint#Handle(bufnr(''), [ \ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)', \ ]) @@ -54,6 +54,6 @@ Execute(The yamllint handler should respect ale_warn_about_trailing_whitespace): AssertEqual \ [ \ ], - \ ale_linters#yaml#yamllint#Handle(bufnr(''), [ + \ ale#handlers#yamllint#Handle(bufnr(''), [ \ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)', \ ]) -- cgit v1.2.3 From 4aa11cbc055ccbc18d2d48a944566b08d6815583 Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Fri, 15 May 2020 09:15:57 +0900 Subject: Improve documentation --- doc/ale-openapi.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/ale-openapi.txt b/doc/ale-openapi.txt index 27261de6..a1137ed8 100644 --- a/doc/ale-openapi.txt +++ b/doc/ale-openapi.txt @@ -15,7 +15,27 @@ Install ibm-openapi-validator either globally or locally: > npm install ibm-openapi-validator -g # global npm install ibm-openapi-validator # local < -Recommended plugin for openapi filetype detection: +Configuration +------------------------------------------------------------------------------- + +OpenAPI files can be written in YAML or JSON so in order for ALE plugins to +work with these files we must set the buffer |filetype| to either |openapi.yaml| +or |openapi.json| respectively. This causes ALE to lint the file with linters +configured for openapi and yaml files or openapi and json files respectively. + +For example setting filetype to |openapi.yaml| on a buffer and the following +|g:ale_linters| configuration will enable linting of openapi files using both +|ibm-validator| and |yamlint|: + +> + let g:ale_linters = { + \ 'yaml': ['yamllint'], + \ 'openapi': ['ibm-validator'] + \} +< + +The following plugin will detect openapi files automatically and set the +filetype to |openapi.yaml| or |openapi.json|: https://github.com/hsanson/vim-openapi -- cgit v1.2.3 From 9bc4b468c20e91350cf1a6d3739f91f504e230ed Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Fri, 22 Jan 2021 23:51:29 +0900 Subject: Fix linter error --- ale_linters/openapi/ibm_validator.vim | 2 +- doc/ale-openapi.txt | 6 +++--- doc/ale-supported-languages-and-tools.txt | 2 +- doc/ale.txt | 2 +- supported-tools.md | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ale_linters/openapi/ibm_validator.vim b/ale_linters/openapi/ibm_validator.vim index c54741d2..446931a2 100644 --- a/ale_linters/openapi/ibm_validator.vim +++ b/ale_linters/openapi/ibm_validator.vim @@ -51,7 +51,7 @@ function! ale_linters#openapi#ibm_validator#Handle(buffer, lines) abort endfunction call ale#linter#Define('openapi', { -\ 'name': 'ibm-validator', +\ 'name': 'ibm_validator', \ 'executable': {b -> ale#Var(b, 'openapi_ibm_validator_executable')}, \ 'command': function('ale_linters#openapi#ibm_validator#GetCommand'), \ 'callback': 'ale_linters#openapi#ibm_validator#Handle', diff --git a/doc/ale-openapi.txt b/doc/ale-openapi.txt index a1137ed8..1fc41add 100644 --- a/doc/ale-openapi.txt +++ b/doc/ale-openapi.txt @@ -2,7 +2,7 @@ ALE OpenApi Integration *ale-openapi-options* =============================================================================== -ibm-validator *ale-openapi-ibm-validator* +ibm_validator *ale-openapi-ibm-validator* Website: https://github.com/IBM/openapi-validator @@ -25,12 +25,12 @@ configured for openapi and yaml files or openapi and json files respectively. For example setting filetype to |openapi.yaml| on a buffer and the following |g:ale_linters| configuration will enable linting of openapi files using both -|ibm-validator| and |yamlint|: +|ibm_validator| and |yamlint|: > let g:ale_linters = { \ 'yaml': ['yamllint'], - \ 'openapi': ['ibm-validator'] + \ 'openapi': ['ibm_validator'] \} < diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 57eb71dc..13538b03 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -323,7 +323,7 @@ Notes: * `ocp-indent` * `ols` * OpenApi - * `ibm-validator` + * `ibm_validator` * `prettier` * `yamllint` * Pawn diff --git a/doc/ale.txt b/doc/ale.txt index b2cea4cd..cfb5beb4 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2836,7 +2836,7 @@ documented in additional help files. ocamlformat...........................|ale-ocaml-ocamlformat| ocp-indent............................|ale-ocaml-ocp-indent| openapi.................................|ale-openapi-options| - ibm-validator.........................|ale-openapi-ibm-validator| + ibm_validator.........................|ale-openapi-ibm-validator| prettier..............................|ale-openapi-prettier| yamllint..............................|ale-openapi-yamllint| pawn....................................|ale-pawn-options| diff --git a/supported-tools.md b/supported-tools.md index df9071f8..0cea2a1b 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -332,7 +332,7 @@ formatting. * [ocp-indent](https://github.com/OCamlPro/ocp-indent) * [ols](https://github.com/freebroccolo/ocaml-language-server) * OpenApi - * [ibm-validator](https://github.com/IBM/openapi-validator) + * [ibm_validator](https://github.com/IBM/openapi-validator) * [prettier](https://github.com/prettier/prettier) * [yamllint](https://yamllint.readthedocs.io/) * Pawn -- cgit v1.2.3 From 4ed520a2192cfee9b93f329e46a0a57c2bd2e771 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 15:42:38 +0900 Subject: add initial files --- ale_linters/vala/vala_lint.vim | 44 +++++++++++++++++++++++++++++++ test/handler/test_vala_lint_handler.vader | 37 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 ale_linters/vala/vala_lint.vim create mode 100644 test/handler/test_vala_lint_handler.vader diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim new file mode 100644 index 00000000..4aad4dcd --- /dev/null +++ b/ale_linters/vala/vala_lint.vim @@ -0,0 +1,44 @@ +" Author: Atsuya Takagi +" Description: A linter for Vala using Vala-Lint. + +function! ale_linters#vala#vala_lint#GetCommand(buffer) abort + return 'io.elementary.vala-lint' +endfunction + +function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort + let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + let l:line = l:match[1] + 0 + let l:column = l:match[2] + 0 + let l:type = 'E' + let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') + let l:code = l:match[5] + + call add(l:output, { + \ 'lnum': l:line, + \ 'col': l:column, + \ 'text': l:text, + \ 'type': l:type, + \ 'code': l:code, + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('vala', { +\ 'name': 'vala-lint', +\ 'output_stream': 'both', +\ 'executable': 'io.elementary.vala-lint', +\ 'command': function('ale_linters#vala#vala_lint#GetCommand'), +\ 'callback': 'ale_linters#vala#vala_lint#Handle', +\ 'lint_file': 1, +\}) diff --git a/test/handler/test_vala_lint_handler.vader b/test/handler/test_vala_lint_handler.vader new file mode 100644 index 00000000..cee8674a --- /dev/null +++ b/test/handler/test_vala_lint_handler.vader @@ -0,0 +1,37 @@ +Before: + runtime ale_linters/vala/vala_lint.vim + +After: + call ale#linter#Reset() + +Execute(The Vala-Lint handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 18, + \ 'col': 18, + \ 'text': 'Expected space before paren', + \ 'code': 'space-before-paren', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 64, + \ 'col': 37, + \ 'text': 'Expected space before paren', + \ 'code': 'space-before-paren', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 73, + \ 'col': 37, + \ 'text': 'Expected space before paren', + \ 'code': 'space-before-paren', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#vala#vala_lint#Handle(bufnr(''), [ + \ 'Application.vala', + \ ' 18.18 error Expected space before paren space-before-paren', + \ ' 64.37 error Expected space before paren space-before-paren', + \ ' 73.37 error Expected space before paren space-before-paren', + \ ]) -- cgit v1.2.3 From 3e820207e7d637a86a16dfce3e2d4fa698b0811d Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 15:52:10 +0900 Subject: be precise about output_stream --- ale_linters/vala/vala_lint.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 4aad4dcd..42434651 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -36,7 +36,7 @@ endfunction call ale#linter#Define('vala', { \ 'name': 'vala-lint', -\ 'output_stream': 'both', +\ 'output_stream': 'stdout', \ 'executable': 'io.elementary.vala-lint', \ 'command': function('ale_linters#vala#vala_lint#GetCommand'), \ 'callback': 'ale_linters#vala#vala_lint#Handle', -- cgit v1.2.3 From 7f1dd5f66ab207676baf79e22edc5e42309306ec Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 16:02:35 +0900 Subject: specify a filename of the current buffer --- ale_linters/vala/vala_lint.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 42434651..8658c17c 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -2,7 +2,7 @@ " Description: A linter for Vala using Vala-Lint. function! ale_linters#vala#vala_lint#GetCommand(buffer) abort - return 'io.elementary.vala-lint' + return 'io.elementary.vala-lint %s' endfunction function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort -- cgit v1.2.3 From e94d23b1d906df77453f111f7e7984385c20eaa2 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 16:38:45 +0900 Subject: test my hypotethis --- ale_linters/vala/vala_lint.vim | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 8658c17c..5b512ad0 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -9,27 +9,35 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)' let l:output = [] - for l:line in a:lines - let l:match = matchlist(l:line, l:pattern) - - if len(l:match) == 0 - continue - endif - - let l:line = l:match[1] + 0 - let l:column = l:match[2] + 0 - let l:type = 'E' - let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') - let l:code = l:match[5] - - call add(l:output, { - \ 'lnum': l:line, - \ 'col': l:column, - \ 'text': l:text, - \ 'type': l:type, - \ 'code': l:code, - \}) - endfor + call add(l:output, { + \ 'lnum': 12, + \ 'col': 30, + \ 'text': 'bad', + \ 'type': 'E', + \ 'code': 'testcode', + \}) + + "for l:line in a:lines + " let l:match = matchlist(l:line, l:pattern) + + " if len(l:match) == 0 + " continue + " endif + + " let l:line = l:match[1] + 0 + " let l:column = l:match[2] + 0 + " let l:type = 'E' + " let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') + " let l:code = l:match[5] + + " call add(l:output, { + " \ 'lnum': l:line, + " \ 'col': l:column, + " \ 'text': l:text, + " \ 'type': l:type, + " \ 'code': l:code, + " \}) + "endfor return l:output endfunction -- cgit v1.2.3 From 9eb6dace889174c61fbaa13ed3c59d91172b5c60 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 16:48:54 +0900 Subject: escape color sequences --- ale_linters/vala/vala_lint.vim | 55 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 5b512ad0..f102d567 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -9,35 +9,32 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)' let l:output = [] - call add(l:output, { - \ 'lnum': 12, - \ 'col': 30, - \ 'text': 'bad', - \ 'type': 'E', - \ 'code': 'testcode', - \}) - - "for l:line in a:lines - " let l:match = matchlist(l:line, l:pattern) - - " if len(l:match) == 0 - " continue - " endif - - " let l:line = l:match[1] + 0 - " let l:column = l:match[2] + 0 - " let l:type = 'E' - " let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') - " let l:code = l:match[5] - - " call add(l:output, { - " \ 'lnum': l:line, - " \ 'col': l:column, - " \ 'text': l:text, - " \ 'type': l:type, - " \ 'code': l:code, - " \}) - "endfor + for l:line in a:lines + " remove color escape sequences since vala-lint doesn't support + " output without colors + let l:cleaned_line = substitute(l:line, '\x1b\[[0-9;]*m', '', 'g') + execute 'echo l:line' + execute 'echo l:cleaned_line' + let l:match = matchlist(l:cleaned, l:pattern) + + if len(l:match) == 0 + continue + endif + + let l:lnum = l:match[1] + 0 + let l:column = l:match[2] + 0 + let l:type = 'E' + let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') + let l:code = l:match[5] + + call add(l:output, { + \ 'lnum': l:lnum, + \ 'col': l:column, + \ 'text': l:text, + \ 'type': l:type, + \ 'code': l:code, + \}) + endfor return l:output endfunction -- cgit v1.2.3 From b3010ad7930344a06163a99182c21e4c768f8a23 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 16:54:06 +0900 Subject: fix the wrong variable name --- ale_linters/vala/vala_lint.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index f102d567..0940f294 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -15,7 +15,7 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort let l:cleaned_line = substitute(l:line, '\x1b\[[0-9;]*m', '', 'g') execute 'echo l:line' execute 'echo l:cleaned_line' - let l:match = matchlist(l:cleaned, l:pattern) + let l:match = matchlist(l:cleaned_line, l:pattern) if len(l:match) == 0 continue -- cgit v1.2.3 From c15d9538cda6ac4bc7cd258b2a0a271ed22ac350 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 2 Jan 2021 17:28:06 +0900 Subject: use the correct regex to match the escape sequences... --- ale_linters/vala/vala_lint.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 0940f294..b0c86fcc 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -12,9 +12,7 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort for l:line in a:lines " remove color escape sequences since vala-lint doesn't support " output without colors - let l:cleaned_line = substitute(l:line, '\x1b\[[0-9;]*m', '', 'g') - execute 'echo l:line' - execute 'echo l:cleaned_line' + let l:cleaned_line = substitute(l:line, '\e\[[0-9;]\+[mK]', '', 'g') let l:match = matchlist(l:cleaned_line, l:pattern) if len(l:match) == 0 -- cgit v1.2.3 From 280d2dedaeba09aad139e9b2c6ea37e3213083b4 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 15:49:29 +0900 Subject: find and use vala-lint config if exists --- ale_linters/vala/vala_lint.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index b0c86fcc..b53e9b86 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -2,7 +2,14 @@ " Description: A linter for Vala using Vala-Lint. function! ale_linters#vala#vala_lint#GetCommand(buffer) abort - return 'io.elementary.vala-lint %s' + let l:command = 'io.elementary.vala-lint ' + + let l:config_path = ale#path#FindNearestFile(a:buffer, 'vala-lint.conf') + if !empty(l:config_path) + let l:command .= '-c ' . l:config_path . ' ' + endif + + return l:command . '%s' endfunction function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort -- cgit v1.2.3 From 89403b4a0600011ad94d51a7aef9e26afe284fd6 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 16:00:30 +0900 Subject: expect warn or error --- ale_linters/vala/vala_lint.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index b53e9b86..a38bf9bf 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -13,7 +13,7 @@ function! ale_linters#vala#vala_lint#GetCommand(buffer) abort endfunction function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort - let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)' + let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(error\|warn\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)' let l:output = [] for l:line in a:lines @@ -26,10 +26,13 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort continue endif + let l:refined_type = l:match[3] is# 'warn' ? 'W' : 'E' + let l:cleaned_text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') + let l:lnum = l:match[1] + 0 let l:column = l:match[2] + 0 - let l:type = 'E' - let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '') + let l:type = l:refined_type + let l:text = l:cleaned_text let l:code = l:match[5] call add(l:output, { -- cgit v1.2.3 From 823b094f5618c9dd53a0a56bbf131ed077f4105b Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 16:17:33 +0900 Subject: support flags for enable/disable config --- ale_linters/vala/vala_lint.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index a38bf9bf..24ade378 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -1,12 +1,18 @@ " Author: Atsuya Takagi " Description: A linter for Vala using Vala-Lint. +let g:ale_vala_vala_lint_enable_config = get(g:, 'ale_vala_vala_lint_enable_config', 0) +let g:ale_vala_vala_lint_config_filename = get(g:, 'ale_vala_vala_lint_config_filename', 'vala-lint.conf') + function! ale_linters#vala#vala_lint#GetCommand(buffer) abort let l:command = 'io.elementary.vala-lint ' - let l:config_path = ale#path#FindNearestFile(a:buffer, 'vala-lint.conf') - if !empty(l:config_path) - let l:command .= '-c ' . l:config_path . ' ' + if ale#Var(a:buffer, 'vala_vala_lint_enable_config') + let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename') + let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename) + if !empty(l:config_path) + let l:command .= '-c ' . l:config_path . ' ' + endif endif return l:command . '%s' -- cgit v1.2.3 From ed2afafd621503f684c31a5e6e75e358f7ccb6ef Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 16:28:51 +0900 Subject: use ale#Set for setting default config variable values --- ale_linters/vala/vala_lint.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 24ade378..d540323c 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -1,8 +1,8 @@ " Author: Atsuya Takagi " Description: A linter for Vala using Vala-Lint. -let g:ale_vala_vala_lint_enable_config = get(g:, 'ale_vala_vala_lint_enable_config', 0) -let g:ale_vala_vala_lint_config_filename = get(g:, 'ale_vala_vala_lint_config_filename', 'vala-lint.conf') +call ale#Set('vala_vala_lint_enable_config', 0) +call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf') function! ale_linters#vala#vala_lint#GetCommand(buffer) abort let l:command = 'io.elementary.vala-lint ' -- cgit v1.2.3 From 67c3fa9001c28ea19e1ac09bd733680fb8df4c24 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 16:44:32 +0900 Subject: add documentation for vala-lint --- doc/ale-vala.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/ale-vala.txt b/doc/ale-vala.txt index ca24bcf4..94bf5400 100644 --- a/doc/ale-vala.txt +++ b/doc/ale-vala.txt @@ -8,5 +8,24 @@ uncrustify *ale-vala-uncrustify* See |ale-c-uncrustify| for information about the available options. +=============================================================================== +Vala-Lint *ale-vala-vala-lint* + +g:ale_vala_vala_lint_enable_config *g:vala_vala_lint_enable_config* + *b:vala_vala_lint_enable_config* + Type: |Number| + Default: `'0'` + + This variable can be set to enable or diable the use of Vala-Lint config file. + + +g:vala_vala_lint_config_filename *g:vala_vala_lint_config_filename* + *b:vala_vala_lint_config_filename* + Type: |String| + Default: `'vala-lint.conf'` + + This variable can be set to specify a Vala-Lint config filename. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: -- cgit v1.2.3 From 2dbf4ee271600a7e243a6d475c57bf54958e904e Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Mon, 4 Jan 2021 16:45:12 +0900 Subject: add test to check if it properly ignores outputs with unknown error types --- test/handler/test_vala_lint_handler.vader | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/handler/test_vala_lint_handler.vader b/test/handler/test_vala_lint_handler.vader index cee8674a..b8a4fbfa 100644 --- a/test/handler/test_vala_lint_handler.vader +++ b/test/handler/test_vala_lint_handler.vader @@ -19,7 +19,7 @@ Execute(The Vala-Lint handler should parse lines correctly): \ 'col': 37, \ 'text': 'Expected space before paren', \ 'code': 'space-before-paren', - \ 'type': 'E', + \ 'type': 'W', \ }, \ { \ 'lnum': 73, @@ -32,6 +32,23 @@ Execute(The Vala-Lint handler should parse lines correctly): \ ale_linters#vala#vala_lint#Handle(bufnr(''), [ \ 'Application.vala', \ ' 18.18 error Expected space before paren space-before-paren', - \ ' 64.37 error Expected space before paren space-before-paren', + \ ' 64.37 warn Expected space before paren space-before-paren', + \ ' 73.37 error Expected space before paren space-before-paren', + \ ]) + +Execute(The Vala-Lint handler should ignore unknown error types): + AssertEqual + \ [ + \ { + \ 'lnum': 73, + \ 'col': 37, + \ 'text': 'Expected space before paren', + \ 'code': 'space-before-paren', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#vala#vala_lint#Handle(bufnr(''), [ + \ 'Application.vala', + \ ' 18.18 test Expected space before paren space-before-paren', \ ' 73.37 error Expected space before paren space-before-paren', \ ]) -- cgit v1.2.3 From 04550717bf023db549c67510c7df429d154f3934 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Tue, 5 Jan 2021 17:49:43 +0900 Subject: add Vala-Lint as supported linter --- doc/ale-supported-languages-and-tools.txt | 1 + supported-tools.md | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 5476be47..d8d10379 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -501,6 +501,7 @@ Notes: * `typecheck` * VALA * `uncrustify` + * `vala-lint`!! * Verilog * `hdl-checker` * `iverilog` diff --git a/supported-tools.md b/supported-tools.md index b07f6acf..21035ffb 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -510,6 +510,7 @@ formatting. * typecheck * VALA * [uncrustify](https://github.com/uncrustify/uncrustify) + * [vala-lint](https://github.com/vala-lang/vala-lint) :floppy_disk: * Verilog * [hdl-checker](https://pypi.org/project/hdl-checker) * [iverilog](https://github.com/steveicarus/iverilog) -- cgit v1.2.3 From 4328fe7dca248266a5cbaa0546581f37d0cf4c64 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Tue, 5 Jan 2021 17:51:59 +0900 Subject: add a blank line before if statement --- ale_linters/vala/vala_lint.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index d540323c..45e9b7d8 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -10,6 +10,7 @@ function! ale_linters#vala#vala_lint#GetCommand(buffer) abort if ale#Var(a:buffer, 'vala_vala_lint_enable_config') let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename') let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename) + if !empty(l:config_path) let l:command .= '-c ' . l:config_path . ' ' endif -- cgit v1.2.3 From e3e1ddce9558ddad360f1109d48ff9c7c66e4e19 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Thu, 14 Jan 2021 09:52:36 +0900 Subject: allow setting vala-lint executable --- ale_linters/vala/vala_lint.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 45e9b7d8..39879303 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -3,9 +3,14 @@ call ale#Set('vala_vala_lint_enable_config', 0) call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf') +call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint') + +function! ale_linters#vala#vala_lint#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'vala_vala_lint_executable') +endfunction function! ale_linters#vala#vala_lint#GetCommand(buffer) abort - let l:command = 'io.elementary.vala-lint ' + let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer) if ale#Var(a:buffer, 'vala_vala_lint_enable_config') let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename') @@ -57,7 +62,7 @@ endfunction call ale#linter#Define('vala', { \ 'name': 'vala-lint', \ 'output_stream': 'stdout', -\ 'executable': 'io.elementary.vala-lint', +\ 'executable': function('ale_linters#vala#vala_lint#GetExecutable'), \ 'command': function('ale_linters#vala#vala_lint#GetCommand'), \ 'callback': 'ale_linters#vala#vala_lint#Handle', \ 'lint_file': 1, -- cgit v1.2.3 From 8d5b3e827df3fa21de32cd367dca95b76f9b0199 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Thu, 14 Jan 2021 09:54:01 +0900 Subject: decide whether or not to run with config file based on the presence of config filename value --- ale_linters/vala/vala_lint.vim | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 39879303..4c39ba42 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -1,7 +1,6 @@ " Author: Atsuya Takagi " Description: A linter for Vala using Vala-Lint. -call ale#Set('vala_vala_lint_enable_config', 0) call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf') call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint') @@ -12,16 +11,14 @@ endfunction function! ale_linters#vala#vala_lint#GetCommand(buffer) abort let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer) - if ale#Var(a:buffer, 'vala_vala_lint_enable_config') - let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename') - let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename) + let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename') + let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename) - if !empty(l:config_path) - let l:command .= '-c ' . l:config_path . ' ' - endif + if !empty(l:config_path) + let l:command .= ' -c ' . l:config_path endif - return l:command . '%s' + return l:command . ' %s' endfunction function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort -- cgit v1.2.3 From 33485ffb92e3718978793d24850d2adb2b08dbc2 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Thu, 14 Jan 2021 09:54:26 +0900 Subject: document the variables can be set for the linter --- doc/ale-vala.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/ale-vala.txt b/doc/ale-vala.txt index 94bf5400..d48f68bb 100644 --- a/doc/ale-vala.txt +++ b/doc/ale-vala.txt @@ -11,12 +11,12 @@ See |ale-c-uncrustify| for information about the available options. =============================================================================== Vala-Lint *ale-vala-vala-lint* -g:ale_vala_vala_lint_enable_config *g:vala_vala_lint_enable_config* - *b:vala_vala_lint_enable_config* - Type: |Number| - Default: `'0'` +g:vala_vala_lint_executable *g:vala_vala_lint_executable* + *b:vala_vala_lint_executable* + Type: |String| + Default: `'io.elementary.vala-lint'` - This variable can be set to enable or diable the use of Vala-Lint config file. + This variable can be set to specify a Vala-Lint executable file. g:vala_vala_lint_config_filename *g:vala_vala_lint_config_filename* @@ -24,7 +24,9 @@ g:vala_vala_lint_config_filename *g:vala_vala_lint_config_filename* Type: |String| Default: `'vala-lint.conf'` - This variable can be set to specify a Vala-Lint config filename. + This variable can be set to specify a Vala-Lint config filename. When a file + with the specified name was not found or this variable was set to empty, + Vala-Lint will be executed without specifying a config filename. =============================================================================== -- cgit v1.2.3 From 897f6b2b235f7ed7a6b0df7f228d18b74a7407e0 Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 23 Jan 2021 00:20:11 +0900 Subject: use snake case for linter name --- ale_linters/vala/vala_lint.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim index 4c39ba42..7f8a566a 100644 --- a/ale_linters/vala/vala_lint.vim +++ b/ale_linters/vala/vala_lint.vim @@ -57,7 +57,7 @@ function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort endfunction call ale#linter#Define('vala', { -\ 'name': 'vala-lint', +\ 'name': 'vala_lint', \ 'output_stream': 'stdout', \ 'executable': function('ale_linters#vala#vala_lint#GetExecutable'), \ 'command': function('ale_linters#vala#vala_lint#GetCommand'), -- cgit v1.2.3 From 6b0b8cec79d6805f57ff925923d7157ffb119a5a Mon Sep 17 00:00:00 2001 From: Atsuya Takagi Date: Sat, 23 Jan 2021 00:20:36 +0900 Subject: update doc with snake cased linter name --- doc/ale-supported-languages-and-tools.txt | 2 +- supported-tools.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index d8d10379..6fb17594 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -501,7 +501,7 @@ Notes: * `typecheck` * VALA * `uncrustify` - * `vala-lint`!! + * `vala_lint`!! * Verilog * `hdl-checker` * `iverilog` diff --git a/supported-tools.md b/supported-tools.md index 21035ffb..289c20e8 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -510,7 +510,7 @@ formatting. * typecheck * VALA * [uncrustify](https://github.com/uncrustify/uncrustify) - * [vala-lint](https://github.com/vala-lang/vala-lint) :floppy_disk: + * [vala_lint](https://github.com/vala-lang/vala-lint) :floppy_disk: * Verilog * [hdl-checker](https://pypi.org/project/hdl-checker) * [iverilog](https://github.com/steveicarus/iverilog) -- cgit v1.2.3 From 6bfcb9cdffb86bf1a3e6d26cd1964858ff4bc3dd Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Wed, 8 Apr 2020 17:59:17 -0500 Subject: linters/xo: consolidate xo linters --- ale_linters/javascript/xo.vim | 23 +++--------------- ale_linters/typescript/xo.vim | 23 +++--------------- autoload/ale/handlers/xo.vim | 28 ++++++++++++++++++++++ .../test_xo_command_callback.vader | 10 ++++---- .../test_xots_command_callback.vader | 22 +++++++++++++++++ 5 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 autoload/ale/handlers/xo.vim create mode 100644 test/command_callback/test_xots_command_callback.vader diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim index e24f4a82..5b206df8 100644 --- a/ale_linters/javascript/xo.vim +++ b/ale_linters/javascript/xo.vim @@ -1,26 +1,9 @@ " Author: Daniel Lupu " Description: xo for JavaScript files -call ale#Set('javascript_xo_executable', 'xo') -call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) -call ale#Set('javascript_xo_options', '') - -function! ale_linters#javascript#xo#GetExecutable(buffer) abort - return ale#node#FindExecutable(a:buffer, 'javascript_xo', [ - \ 'node_modules/.bin/xo', - \]) -endfunction - -function! ale_linters#javascript#xo#GetCommand(buffer) abort - return ale#Escape(ale_linters#javascript#xo#GetExecutable(a:buffer)) - \ . ' ' . ale#Var(a:buffer, 'javascript_xo_options') - \ . ' --reporter json --stdin --stdin-filename %s' -endfunction - -" xo uses eslint and the output format is the same call ale#linter#Define('javascript', { \ 'name': 'xo', -\ 'executable': function('ale_linters#javascript#xo#GetExecutable'), -\ 'command': function('ale_linters#javascript#xo#GetCommand'), -\ 'callback': 'ale#handlers#eslint#HandleJSON', +\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'javascript')}, +\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'javascript')}, +\ 'callback': 'ale#handlers#xo#HandleJSON', \}) diff --git a/ale_linters/typescript/xo.vim b/ale_linters/typescript/xo.vim index 0a3a717b..13ae0cf7 100644 --- a/ale_linters/typescript/xo.vim +++ b/ale_linters/typescript/xo.vim @@ -1,23 +1,6 @@ -call ale#Set('typescript_xo_executable', 'xo') -call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) -call ale#Set('typescript_xo_options', '') - -function! ale_linters#typescript#xo#GetExecutable(buffer) abort - return ale#node#FindExecutable(a:buffer, 'typescript_xo', [ - \ 'node_modules/.bin/xo', - \]) -endfunction - -function! ale_linters#typescript#xo#GetCommand(buffer) abort - return ale#Escape(ale_linters#typescript#xo#GetExecutable(a:buffer)) - \ . ale#Pad(ale#Var(a:buffer, 'typescript_xo_options')) - \ . ' --reporter json --stdin --stdin-filename %s' -endfunction - -" xo uses eslint and the output format is the same call ale#linter#Define('typescript', { \ 'name': 'xo', -\ 'executable': function('ale_linters#typescript#xo#GetExecutable'), -\ 'command': function('ale_linters#typescript#xo#GetCommand'), -\ 'callback': 'ale#handlers#eslint#HandleJSON', +\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'typescript')}, +\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'typescript')}, +\ 'callback': 'ale#handlers#xo#HandleJSON', \}) diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim new file mode 100644 index 00000000..38dcf5d5 --- /dev/null +++ b/autoload/ale/handlers/xo.vim @@ -0,0 +1,28 @@ +call ale#Set('javascript_xo_executable', 'xo') +call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('javascript_xo_options', '') + +call ale#Set('typescript_xo_executable', 'xo') +call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('typescript_xo_options', '') + +function! ale#handlers#xo#GetExecutable(buffer, type) abort + return ale#node#FindExecutable(a:buffer, a:type . '_xo', [ + \ 'node_modules/.bin/xo', + \]) +endfunction + +function! ale#handlers#xo#GetLintCommand(buffer, type) abort + return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer, a:type)) + \ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer, a:type)) + \ . ' --reporter json --stdin --stdin-filename %s' +endfunction + +function! ale#handlers#xo#GetOptions(buffer, type) abort + return ale#Var(a:buffer, a:type . '_xo_options') +endfunction + +" xo uses eslint and the output format is the same +function! ale#handlers#xo#HandleJSON(buffer, lines) abort + return ale#handlers#eslint#HandleJSON(a:buffer, a:lines) +endfunction diff --git a/test/command_callback/test_xo_command_callback.vader b/test/command_callback/test_xo_command_callback.vader index 65cb4f8a..7a38b2b1 100644 --- a/test/command_callback/test_xo_command_callback.vader +++ b/test/command_callback/test_xo_command_callback.vader @@ -1,8 +1,10 @@ Before: - call ale#assert#SetUpLinterTest('typescript', 'xo') - call ale#test#SetFilename('testfile.ts') + call ale#assert#SetUpLinterTest('javascript', 'xo') + call ale#test#SetFilename('testfile.js') unlet! b:executable + runtime autoload/ale/handlers/xo.vim + After: call ale#assert#TearDownLinterTest() @@ -10,11 +12,11 @@ Execute(The XO executable should be called): AssertLinter 'xo', ale#Escape('xo') . ' --reporter json --stdin --stdin-filename %s' Execute(The XO executable should be configurable): - let b:ale_typescript_xo_executable = 'foobar' + let b:ale_javascript_xo_executable = 'foobar' AssertLinter 'foobar', ale#Escape('foobar') . ' --reporter json --stdin --stdin-filename %s' Execute(The XO options should be configurable): - let b:ale_typescript_xo_options = '--wat' + let b:ale_javascript_xo_options = '--wat' AssertLinter 'xo', ale#Escape('xo') . ' --wat --reporter json --stdin --stdin-filename %s' diff --git a/test/command_callback/test_xots_command_callback.vader b/test/command_callback/test_xots_command_callback.vader new file mode 100644 index 00000000..c614ad59 --- /dev/null +++ b/test/command_callback/test_xots_command_callback.vader @@ -0,0 +1,22 @@ +Before: + call ale#assert#SetUpLinterTest('typescript', 'xo') + call ale#test#SetFilename('testfile.ts') + unlet! b:executable + + runtime autoload/ale/handlers/xo.vim + +After: + call ale#assert#TearDownLinterTest() + +Execute(The XO executable should be called): + AssertLinter 'xo', ale#Escape('xo') . ' --reporter json --stdin --stdin-filename %s' + +Execute(The XO executable should be configurable): + let b:ale_typescript_xo_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' --reporter json --stdin --stdin-filename %s' + +Execute(The XO options should be configurable): + let b:ale_typescript_xo_options = '--wat' + + AssertLinter 'xo', ale#Escape('xo') . ' --wat --reporter json --stdin --stdin-filename %s' -- cgit v1.2.3 From 4a6136c27ec2430a1ef5481e0ca10dee03ba178f Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Wed, 8 Apr 2020 18:20:10 -0500 Subject: fixers/xo: add tests --- autoload/ale/fixers/xo.vim | 4 ++- .../react-app/node_modules/xo/cli.js | 0 test/fixers/test_xo_fixer_callback.vader | 29 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/eslint-test-files/react-app/node_modules/xo/cli.js create mode 100644 test/fixers/test_xo_fixer_callback.vader diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 882350be..69d23ea3 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -14,10 +14,12 @@ endfunction function! ale#fixers#xo#Fix(buffer) abort let l:executable = ale#fixers#xo#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'javascript_xo_options') return { \ 'command': ale#node#Executable(a:buffer, l:executable) - \ . ' --fix %t', + \ . ' --fix %t' + \ . ale#Pad(l:options), \ 'read_temporary_file': 1, \} endfunction diff --git a/test/eslint-test-files/react-app/node_modules/xo/cli.js b/test/eslint-test-files/react-app/node_modules/xo/cli.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader new file mode 100644 index 00000000..8bccd05e --- /dev/null +++ b/test/fixers/test_xo_fixer_callback.vader @@ -0,0 +1,29 @@ +Before: + call ale#assert#SetUpFixerTest('javascript', 'xo') + +After: + call ale#assert#TearDownFixerTest() + +Execute(The xo callback should return the correct default values): + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + + AssertFixer + \ { + \ 'read_temporary_file': 1, + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --fix %t', + \ } + +Execute(The xo callback should include custom xo options): + let g:ale_javascript_xo_options = '--space' + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + + AssertFixer + \ { + \ 'read_temporary_file': 1, + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --fix %t' + \ . ' --space', + \ } -- cgit v1.2.3 From 289f808ccd3098cb19bc3bbbb274524a4fb85ff7 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Wed, 8 Apr 2020 18:38:47 -0500 Subject: fixers/xo: refactor to handlers --- autoload/ale/fixers/xo.vim | 15 ++------------- autoload/ale/handlers/xo.vim | 1 + test/fixers/test_xo_fixer_callback.vader | 1 + 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 69d23ea3..06e58508 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -1,20 +1,9 @@ " Author: Albert Marquez - https://github.com/a-marquez " Description: Fixing files with XO. -call ale#Set('javascript_xo_executable', 'xo') -call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) -call ale#Set('javascript_xo_options', '') - -function! ale#fixers#xo#GetExecutable(buffer) abort - return ale#node#FindExecutable(a:buffer, 'javascript_xo', [ - \ 'node_modules/xo/cli.js', - \ 'node_modules/.bin/xo', - \]) -endfunction - function! ale#fixers#xo#Fix(buffer) abort - let l:executable = ale#fixers#xo#GetExecutable(a:buffer) - let l:options = ale#Var(a:buffer, 'javascript_xo_options') + let l:executable = ale#handlers#xo#GetExecutable(a:buffer, 'javascript') + let l:options = ale#handlers#xo#GetOptions(a:buffer, 'javascript') return { \ 'command': ale#node#Executable(a:buffer, l:executable) diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 38dcf5d5..3f7c72cb 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -8,6 +8,7 @@ call ale#Set('typescript_xo_options', '') function! ale#handlers#xo#GetExecutable(buffer, type) abort return ale#node#FindExecutable(a:buffer, a:type . '_xo', [ + \ 'node_modules/xo/cli.js', \ 'node_modules/.bin/xo', \]) endfunction diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader index 8bccd05e..0bb3108a 100644 --- a/test/fixers/test_xo_fixer_callback.vader +++ b/test/fixers/test_xo_fixer_callback.vader @@ -1,5 +1,6 @@ Before: call ale#assert#SetUpFixerTest('javascript', 'xo') + runtime autoload/ale/handlers/xo.vim After: call ale#assert#TearDownFixerTest() -- cgit v1.2.3 From e75ac9f4975be35e4f33b955f473ba5e336c9ca0 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Wed, 8 Apr 2020 18:52:53 -0500 Subject: fixers/xo: support typescript options --- autoload/ale/fixers/xo.vim | 13 +++++++-- .../eslint-test-files/react-app/subdir/testfile.ts | 0 test/fixers/test_xo_fixer_callback.vader | 1 + test/fixers/test_xots_fixer_callback.vader | 31 ++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/eslint-test-files/react-app/subdir/testfile.ts create mode 100644 test/fixers/test_xots_fixer_callback.vader diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 06e58508..6c2901db 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -2,8 +2,17 @@ " Description: Fixing files with XO. function! ale#fixers#xo#Fix(buffer) abort - let l:executable = ale#handlers#xo#GetExecutable(a:buffer, 'javascript') - let l:options = ale#handlers#xo#GetOptions(a:buffer, 'javascript') + let l:filetype = getbufvar(a:buffer, '&filetype') + let l:type = '' + + if l:filetype =~# 'javascript' + let l:type = 'javascript' + elseif l:filetype =~# 'typescript' + let l:type = 'typescript' + endif + + let l:executable = ale#handlers#xo#GetExecutable(a:buffer, l:type) + let l:options = ale#handlers#xo#GetOptions(a:buffer, l:type) return { \ 'command': ale#node#Executable(a:buffer, l:executable) diff --git a/test/eslint-test-files/react-app/subdir/testfile.ts b/test/eslint-test-files/react-app/subdir/testfile.ts new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader index 0bb3108a..d36fe74c 100644 --- a/test/fixers/test_xo_fixer_callback.vader +++ b/test/fixers/test_xo_fixer_callback.vader @@ -1,6 +1,7 @@ Before: call ale#assert#SetUpFixerTest('javascript', 'xo') runtime autoload/ale/handlers/xo.vim + set filetype=javascript After: call ale#assert#TearDownFixerTest() diff --git a/test/fixers/test_xots_fixer_callback.vader b/test/fixers/test_xots_fixer_callback.vader new file mode 100644 index 00000000..1ef6a6dd --- /dev/null +++ b/test/fixers/test_xots_fixer_callback.vader @@ -0,0 +1,31 @@ +Before: + call ale#assert#SetUpFixerTest('typescript', 'xo') + runtime autoload/ale/handlers/xo.vim + set filetype=typescript + +After: + call ale#assert#TearDownFixerTest() + +Execute(The xo callback should return the correct default values): + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + + AssertFixer + \ { + \ 'read_temporary_file': 1, + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --fix %t', + \ } + +Execute(The xo callback should include custom xo options): + let g:ale_typescript_xo_options = '--space' + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + + AssertFixer + \ { + \ 'read_temporary_file': 1, + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --fix %t' + \ . ' --space', + \ } -- cgit v1.2.3 From 8ffde14039bdc0c12d1edf961461245eb15858e9 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Wed, 8 Apr 2020 22:59:54 -0500 Subject: fixers/xo: support stdin relative to the fixed file --- autoload/ale/fixers/xo.vim | 29 +++++++++++++++++++++++++++-- autoload/ale/handlers/xo.vim | 6 ++++++ test/fixers/test_xo_fixer_callback.vader | 15 +++++++++++++++ test/fixers/test_xots_fixer_callback.vader | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 6c2901db..2c8ab114 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -14,10 +14,35 @@ function! ale#fixers#xo#Fix(buffer) abort let l:executable = ale#handlers#xo#GetExecutable(a:buffer, l:type) let l:options = ale#handlers#xo#GetOptions(a:buffer, l:type) + return ale#semver#RunWithVersionCheck( + \ a:buffer, + \ l:executable, + \ '%e --version', + \ {b, v -> ale#fixers#xo#ApplyFixForVersion(b, v, l:executable, l:options)} + \) +endfunction + +function! ale#fixers#xo#ApplyFixForVersion(buffer, version, executable, options) abort + let l:executable = ale#node#Executable(a:buffer, a:executable) + let l:options = ale#Pad(a:options) + + " 0.30.0 is the first version with a working --stdin --fix + if ale#semver#GTE(a:version, [0, 30, 0]) + let l:project_root = ale#handlers#xo#GetProjectRoot(a:buffer) + + return { + \ 'command': ale#path#CdString(l:project_root) + \ . l:executable + \ . ' --stdin --stdin-filename %s' + \ . ' --fix' + \ . l:options, + \} + endif + return { - \ 'command': ale#node#Executable(a:buffer, l:executable) + \ 'command': l:executable \ . ' --fix %t' - \ . ale#Pad(l:options), + \ . l:options, \ 'read_temporary_file': 1, \} endfunction diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 3f7c72cb..0bea74e4 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -27,3 +27,9 @@ endfunction function! ale#handlers#xo#HandleJSON(buffer, lines) abort return ale#handlers#eslint#HandleJSON(a:buffer, a:lines) endfunction + +function! ale#handlers#xo#GetProjectRoot(buffer) abort + let l:package_path = ale#path#FindNearestFile(a:buffer, 'package.json') + + return empty(l:package_path) ? '' : fnamemodify(l:package_path, ':p:h') +endfunction diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader index d36fe74c..ffbecb6c 100644 --- a/test/fixers/test_xo_fixer_callback.vader +++ b/test/fixers/test_xo_fixer_callback.vader @@ -29,3 +29,18 @@ Execute(The xo callback should include custom xo options): \ . ' --fix %t' \ . ' --space', \ } + +Execute(--stdin should be used when xo is new enough): + let g:ale_javascript_xo_options = '--space' + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + + GivenCommandOutput ['0.30.0'] + AssertFixer + \ { + \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files')) + \ . (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --stdin --stdin-filename %s' + \ . ' --fix' + \ . ' --space', + \ } diff --git a/test/fixers/test_xots_fixer_callback.vader b/test/fixers/test_xots_fixer_callback.vader index 1ef6a6dd..a26ec03c 100644 --- a/test/fixers/test_xots_fixer_callback.vader +++ b/test/fixers/test_xots_fixer_callback.vader @@ -29,3 +29,18 @@ Execute(The xo callback should include custom xo options): \ . ' --fix %t' \ . ' --space', \ } + +Execute(--stdin should be used when xo is new enough): + let g:ale_typescript_xo_options = '--space' + call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + + GivenCommandOutput ['0.30.0'] + AssertFixer + \ { + \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files')) + \ . (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ' --stdin --stdin-filename %s' + \ . ' --fix' + \ . ' --space', + \ } -- cgit v1.2.3 From f17beadb49a6e57520303ea9a10722df1be4d13e Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Mon, 29 Jun 2020 18:40:43 -0500 Subject: fixers/xo: support monorepos --- autoload/ale/handlers/xo.vim | 4 ++-- test/fixers/test_xo_fixer_callback.vader | 14 +++++++------- test/fixers/test_xots_fixer_callback.vader | 14 +++++++------- test/xo-test-files/monorepo/node_modules/xo/cli.js | 0 test/xo-test-files/monorepo/package.json | 0 test/xo-test-files/monorepo/packages/a/index.js | 0 test/xo-test-files/monorepo/packages/a/index.ts | 0 test/xo-test-files/monorepo/packages/a/package.json | 0 8 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 test/xo-test-files/monorepo/node_modules/xo/cli.js create mode 100644 test/xo-test-files/monorepo/package.json create mode 100644 test/xo-test-files/monorepo/packages/a/index.js create mode 100644 test/xo-test-files/monorepo/packages/a/index.ts create mode 100644 test/xo-test-files/monorepo/packages/a/package.json diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 0bea74e4..df2659da 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -29,7 +29,7 @@ function! ale#handlers#xo#HandleJSON(buffer, lines) abort endfunction function! ale#handlers#xo#GetProjectRoot(buffer) abort - let l:package_path = ale#path#FindNearestFile(a:buffer, 'package.json') + let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules') - return empty(l:package_path) ? '' : fnamemodify(l:package_path, ':p:h') + return empty(l:modules_dir) ? '' : fnamemodify(l:modules_dir, ':h:h') endfunction diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader index ffbecb6c..c676bd34 100644 --- a/test/fixers/test_xo_fixer_callback.vader +++ b/test/fixers/test_xo_fixer_callback.vader @@ -7,39 +7,39 @@ After: call ale#assert#TearDownFixerTest() Execute(The xo callback should return the correct default values): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.js') AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --fix %t', \ } Execute(The xo callback should include custom xo options): let g:ale_javascript_xo_options = '--space' - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.js') AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --fix %t' \ . ' --space', \ } Execute(--stdin should be used when xo is new enough): let g:ale_javascript_xo_options = '--space' - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.js') GivenCommandOutput ['0.30.0'] AssertFixer \ { - \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files')) + \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo')) \ . (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --stdin --stdin-filename %s' \ . ' --fix' \ . ' --space', diff --git a/test/fixers/test_xots_fixer_callback.vader b/test/fixers/test_xots_fixer_callback.vader index a26ec03c..6c8b448c 100644 --- a/test/fixers/test_xots_fixer_callback.vader +++ b/test/fixers/test_xots_fixer_callback.vader @@ -7,39 +7,39 @@ After: call ale#assert#TearDownFixerTest() Execute(The xo callback should return the correct default values): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.ts') AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --fix %t', \ } Execute(The xo callback should include custom xo options): let g:ale_typescript_xo_options = '--space' - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.ts') AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --fix %t' \ . ' --space', \ } Execute(--stdin should be used when xo is new enough): let g:ale_typescript_xo_options = '--space' - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts') + call ale#test#SetFilename('../xo-test-files/monorepo/packages/a/index.ts') GivenCommandOutput ['0.30.0'] AssertFixer \ { - \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../eslint-test-files')) + \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo')) \ . (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js')) + \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --stdin --stdin-filename %s' \ . ' --fix' \ . ' --space', diff --git a/test/xo-test-files/monorepo/node_modules/xo/cli.js b/test/xo-test-files/monorepo/node_modules/xo/cli.js new file mode 100644 index 00000000..e69de29b diff --git a/test/xo-test-files/monorepo/package.json b/test/xo-test-files/monorepo/package.json new file mode 100644 index 00000000..e69de29b diff --git a/test/xo-test-files/monorepo/packages/a/index.js b/test/xo-test-files/monorepo/packages/a/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/xo-test-files/monorepo/packages/a/index.ts b/test/xo-test-files/monorepo/packages/a/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/test/xo-test-files/monorepo/packages/a/package.json b/test/xo-test-files/monorepo/packages/a/package.json new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From 1991313ee734129d056a61d6daf1da2c738f8e1a Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Sat, 4 Jul 2020 14:11:16 -0500 Subject: xo: update docs --- doc/ale-typescript.txt | 27 +++++++++++++++++++++++++++ doc/ale.txt | 1 + 2 files changed, 28 insertions(+) diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt index 2c50d119..026d17ce 100644 --- a/doc/ale-typescript.txt +++ b/doc/ale-typescript.txt @@ -138,5 +138,32 @@ g:ale_typescript_tsserver_use_global *g:ale_typescript_tsserver_use_global* tsserver in node_modules. +=============================================================================== +xo *ale-typescript-xo* + +g:ale_typescript_xo_executable *g:ale_typescript_xo_executable* + *b:ale_typescript_xo_executable* + Type: |String| + Default: `'xo'` + + See |ale-integrations-local-executables| + + +g:ale_typescript_xo_options *g:ale_typescript_xo_options* + *b:ale_typescript_xo_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to xo. + + +g:ale_typescript_xo_use_global *g:ale_typescript_xo_use_global* + *b:ale_typescript_xo_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index cfb5beb4..817201c4 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2997,6 +2997,7 @@ documented in additional help files. standard..............................|ale-typescript-standard| tslint................................|ale-typescript-tslint| tsserver..............................|ale-typescript-tsserver| + xo....................................|ale-typescript-xo| vala....................................|ale-vala-options| uncrustify............................|ale-vala-uncrustify| verilog/systemverilog...................|ale-verilog-options| -- cgit v1.2.3 From 23ff19a162aadb048f3d5b2d4a4aa9cf3ec58a52 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Sat, 4 Jul 2020 14:12:14 -0500 Subject: fixers/xo: remove unnecessary directory crawl --- autoload/ale/fixers/xo.vim | 5 +---- autoload/ale/handlers/xo.vim | 6 ------ test/fixers/test_xo_fixer_callback.vader | 3 +-- test/fixers/test_xots_fixer_callback.vader | 3 +-- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 2c8ab114..0f8f3ec6 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -28,11 +28,8 @@ function! ale#fixers#xo#ApplyFixForVersion(buffer, version, executable, options) " 0.30.0 is the first version with a working --stdin --fix if ale#semver#GTE(a:version, [0, 30, 0]) - let l:project_root = ale#handlers#xo#GetProjectRoot(a:buffer) - return { - \ 'command': ale#path#CdString(l:project_root) - \ . l:executable + \ 'command': l:executable \ . ' --stdin --stdin-filename %s' \ . ' --fix' \ . l:options, diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index df2659da..3f7c72cb 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -27,9 +27,3 @@ endfunction function! ale#handlers#xo#HandleJSON(buffer, lines) abort return ale#handlers#eslint#HandleJSON(a:buffer, a:lines) endfunction - -function! ale#handlers#xo#GetProjectRoot(buffer) abort - let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules') - - return empty(l:modules_dir) ? '' : fnamemodify(l:modules_dir, ':h:h') -endfunction diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader index c676bd34..a473606e 100644 --- a/test/fixers/test_xo_fixer_callback.vader +++ b/test/fixers/test_xo_fixer_callback.vader @@ -37,8 +37,7 @@ Execute(--stdin should be used when xo is new enough): GivenCommandOutput ['0.30.0'] AssertFixer \ { - \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo')) - \ . (has('win32') ? 'node.exe ' : '') + \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --stdin --stdin-filename %s' \ . ' --fix' diff --git a/test/fixers/test_xots_fixer_callback.vader b/test/fixers/test_xots_fixer_callback.vader index 6c8b448c..5c7fa1d1 100644 --- a/test/fixers/test_xots_fixer_callback.vader +++ b/test/fixers/test_xots_fixer_callback.vader @@ -37,8 +37,7 @@ Execute(--stdin should be used when xo is new enough): GivenCommandOutput ['0.30.0'] AssertFixer \ { - \ 'command': ale#path#CdString(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo')) - \ . (has('win32') ? 'node.exe ' : '') + \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../xo-test-files/monorepo/node_modules/xo/cli.js')) \ . ' --stdin --stdin-filename %s' \ . ' --fix' -- cgit v1.2.3 From 4edfac4db64debcfd33d894f169d0c1dc6dc48a4 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Tue, 19 Jan 2021 22:16:10 -0600 Subject: xo: inline filetype handling --- ale_linters/javascript/xo.vim | 4 ++-- ale_linters/typescript/xo.vim | 4 ++-- autoload/ale/fixers/xo.vim | 13 ++----------- autoload/ale/handlers/xo.vim | 32 +++++++++++++++++++++++++------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim index 5b206df8..9cc1dc69 100644 --- a/ale_linters/javascript/xo.vim +++ b/ale_linters/javascript/xo.vim @@ -3,7 +3,7 @@ call ale#linter#Define('javascript', { \ 'name': 'xo', -\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'javascript')}, -\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'javascript')}, +\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)}, +\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)}, \ 'callback': 'ale#handlers#xo#HandleJSON', \}) diff --git a/ale_linters/typescript/xo.vim b/ale_linters/typescript/xo.vim index 13ae0cf7..2e25ba4c 100644 --- a/ale_linters/typescript/xo.vim +++ b/ale_linters/typescript/xo.vim @@ -1,6 +1,6 @@ call ale#linter#Define('typescript', { \ 'name': 'xo', -\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'typescript')}, -\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'typescript')}, +\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)}, +\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)}, \ 'callback': 'ale#handlers#xo#HandleJSON', \}) diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim index 0f8f3ec6..dcf4c737 100644 --- a/autoload/ale/fixers/xo.vim +++ b/autoload/ale/fixers/xo.vim @@ -2,17 +2,8 @@ " Description: Fixing files with XO. function! ale#fixers#xo#Fix(buffer) abort - let l:filetype = getbufvar(a:buffer, '&filetype') - let l:type = '' - - if l:filetype =~# 'javascript' - let l:type = 'javascript' - elseif l:filetype =~# 'typescript' - let l:type = 'typescript' - endif - - let l:executable = ale#handlers#xo#GetExecutable(a:buffer, l:type) - let l:options = ale#handlers#xo#GetOptions(a:buffer, l:type) + let l:executable = ale#handlers#xo#GetExecutable(a:buffer) + let l:options = ale#handlers#xo#GetOptions(a:buffer) return ale#semver#RunWithVersionCheck( \ a:buffer, diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 3f7c72cb..2439b4f9 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -6,21 +6,39 @@ call ale#Set('typescript_xo_executable', 'xo') call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('typescript_xo_options', '') -function! ale#handlers#xo#GetExecutable(buffer, type) abort - return ale#node#FindExecutable(a:buffer, a:type . '_xo', [ +function! ale#handlers#xo#GetExecutable(buffer) abort + let l:filetype = getbufvar(a:buffer, '&filetype') + let l:type = '' + + if l:filetype =~# 'javascript' + let l:type = 'javascript' + elseif l:filetype =~# 'typescript' + let l:type = 'typescript' + endif + + return ale#node#FindExecutable(a:buffer, l:type . '_xo', [ \ 'node_modules/xo/cli.js', \ 'node_modules/.bin/xo', \]) endfunction -function! ale#handlers#xo#GetLintCommand(buffer, type) abort - return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer, a:type)) - \ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer, a:type)) +function! ale#handlers#xo#GetLintCommand(buffer) abort + return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer)) + \ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer)) \ . ' --reporter json --stdin --stdin-filename %s' endfunction -function! ale#handlers#xo#GetOptions(buffer, type) abort - return ale#Var(a:buffer, a:type . '_xo_options') +function! ale#handlers#xo#GetOptions(buffer) abort + let l:filetype = getbufvar(a:buffer, '&filetype') + let l:type = '' + + if l:filetype =~# 'javascript' + let l:type = 'javascript' + elseif l:filetype =~# 'typescript' + let l:type = 'typescript' + endif + + return ale#Var(a:buffer, l:type . '_xo_options') endfunction " xo uses eslint and the output format is the same -- cgit v1.2.3 From 5fd5fa53051c3514917974d0ba57f18eb50dd37e Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Tue, 19 Jan 2021 23:08:10 -0600 Subject: linters/xo: fix tests --- test/command_callback/test_xo_command_callback.vader | 3 ++- test/command_callback/test_xots_command_callback.vader | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/command_callback/test_xo_command_callback.vader b/test/command_callback/test_xo_command_callback.vader index 7a38b2b1..1aa4c3f1 100644 --- a/test/command_callback/test_xo_command_callback.vader +++ b/test/command_callback/test_xo_command_callback.vader @@ -1,8 +1,9 @@ Before: call ale#assert#SetUpLinterTest('javascript', 'xo') - call ale#test#SetFilename('testfile.js') + call ale#test#SetFilename('testfile.jsx') unlet! b:executable + set filetype=javascriptreact runtime autoload/ale/handlers/xo.vim After: diff --git a/test/command_callback/test_xots_command_callback.vader b/test/command_callback/test_xots_command_callback.vader index c614ad59..cc38ff02 100644 --- a/test/command_callback/test_xots_command_callback.vader +++ b/test/command_callback/test_xots_command_callback.vader @@ -1,8 +1,9 @@ Before: call ale#assert#SetUpLinterTest('typescript', 'xo') - call ale#test#SetFilename('testfile.ts') + call ale#test#SetFilename('testfile.tsx') unlet! b:executable + set filetype=typescriptreact runtime autoload/ale/handlers/xo.vim After: -- cgit v1.2.3 From 03bd494fd42181f111ee56387a1d40639b42672e Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Tue, 19 Jan 2021 23:07:33 -0600 Subject: linters/xo: prefer function shorthand --- ale_linters/javascript/xo.vim | 4 ++-- ale_linters/typescript/xo.vim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim index 9cc1dc69..5e04ad5c 100644 --- a/ale_linters/javascript/xo.vim +++ b/ale_linters/javascript/xo.vim @@ -3,7 +3,7 @@ call ale#linter#Define('javascript', { \ 'name': 'xo', -\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)}, -\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)}, +\ 'executable': function('ale#handlers#xo#GetExecutable'), +\ 'command': function('ale#handlers#xo#GetLintCommand'), \ 'callback': 'ale#handlers#xo#HandleJSON', \}) diff --git a/ale_linters/typescript/xo.vim b/ale_linters/typescript/xo.vim index 2e25ba4c..6f4ee50c 100644 --- a/ale_linters/typescript/xo.vim +++ b/ale_linters/typescript/xo.vim @@ -1,6 +1,6 @@ call ale#linter#Define('typescript', { \ 'name': 'xo', -\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)}, -\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)}, +\ 'executable': function('ale#handlers#xo#GetExecutable'), +\ 'command': function('ale#handlers#xo#GetLintCommand'), \ 'callback': 'ale#handlers#xo#HandleJSON', \}) -- cgit v1.2.3 From 451e99341ea2abf48ec2e7318748e688a9a93b90 Mon Sep 17 00:00:00 2001 From: Charles B Johnson Date: Tue, 19 Jan 2021 23:07:55 -0600 Subject: xo: refactor to function --- autoload/ale/handlers/xo.vim | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim index 2439b4f9..c63278c0 100644 --- a/autoload/ale/handlers/xo.vim +++ b/autoload/ale/handlers/xo.vim @@ -7,14 +7,7 @@ call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0 call ale#Set('typescript_xo_options', '') function! ale#handlers#xo#GetExecutable(buffer) abort - let l:filetype = getbufvar(a:buffer, '&filetype') - let l:type = '' - - if l:filetype =~# 'javascript' - let l:type = 'javascript' - elseif l:filetype =~# 'typescript' - let l:type = 'typescript' - endif + let l:type = ale#handlers#xo#GetType(a:buffer) return ale#node#FindExecutable(a:buffer, l:type . '_xo', [ \ 'node_modules/xo/cli.js', @@ -29,14 +22,7 @@ function! ale#handlers#xo#GetLintCommand(buffer) abort endfunction function! ale#handlers#xo#GetOptions(buffer) abort - let l:filetype = getbufvar(a:buffer, '&filetype') - let l:type = '' - - if l:filetype =~# 'javascript' - let l:type = 'javascript' - elseif l:filetype =~# 'typescript' - let l:type = 'typescript' - endif + let l:type = ale#handlers#xo#GetType(a:buffer) return ale#Var(a:buffer, l:type . '_xo_options') endfunction @@ -45,3 +31,14 @@ endfunction function! ale#handlers#xo#HandleJSON(buffer, lines) abort return ale#handlers#eslint#HandleJSON(a:buffer, a:lines) endfunction + +function! ale#handlers#xo#GetType(buffer) abort + let l:filetype = getbufvar(a:buffer, '&filetype') + let l:type = 'javascript' + + if l:filetype =~# 'typescript' + let l:type = 'typescript' + endif + + return l:type +endfunction -- cgit v1.2.3 From 35b8bb8a554741e9cd132ae82e9cc4a82f8f361d Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Sun, 22 Mar 2020 20:39:40 +0000 Subject: Add dart analysis server linter --- ale_linters/dart/analysis_server.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ale_linters/dart/analysis_server.vim diff --git a/ale_linters/dart/analysis_server.vim b/ale_linters/dart/analysis_server.vim new file mode 100644 index 00000000..4a0ea4f2 --- /dev/null +++ b/ale_linters/dart/analysis_server.vim @@ -0,0 +1,28 @@ +" Author: Nelson Yeung +" Description: Check Dart files with dart analysis server LSP + +call ale#Set('dart_analysis_server_executable', 'dart') + +function! ale_linters#dart#analysis_server#GetProjectRoot(buffer) abort + " Note: pub only looks for pubspec.yaml, there's no point in adding + " support for pubspec.yml + let l:pubspec = ale#path#FindNearestFile(a:buffer, 'pubspec.yaml') + + return !empty(l:pubspec) ? fnamemodify(l:pubspec, ':h:h') : '' +endfunction + +function! ale_linters#dart#analysis_server#GetCommand(buffer) abort + let l:executable = ale#Var(a:buffer, 'dart_analysis_server_executable') + let l:dart = resolve(exepath(l:executable)) + return '%e ' + \ . fnamemodify(l:dart, ':h') . '/snapshots/analysis_server.dart.snapshot' + \ . ' --lsp' +endfunction + +call ale#linter#Define('dart', { +\ 'name': 'analysis_server', +\ 'lsp': 'stdio', +\ 'executable': {b -> ale#Var(b, 'dart_analysis_server_executable')}, +\ 'command': function('ale_linters#dart#analysis_server#GetCommand'), +\ 'project_root': function('ale_linters#dart#analysis_server#GetProjectRoot'), +\}) -- cgit v1.2.3 From 075c3e0ad02456db17d28f1b04a14e015c63c11b Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Sun, 22 Mar 2020 20:48:39 +0000 Subject: Add dart analysis_server to supported tools --- supported-tools.md | 1 + 1 file changed, 1 insertion(+) diff --git a/supported-tools.md b/supported-tools.md index ff4a78d8..8ed83d6c 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -125,6 +125,7 @@ formatting. * Dafny * [dafny](https://rise4fun.com/Dafny) :floppy_disk: * Dart + * [analysis_server](https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server) * [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk: * [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt) * [language_server](https://github.com/natebosch/dart_language_server) -- cgit v1.2.3 From 847f729cd4e608e6feb81a342bec6cb3745c9845 Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Sun, 22 Mar 2020 21:02:47 +0000 Subject: Add dart analysis_server doc --- doc/ale-dart.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/ale-dart.txt b/doc/ale-dart.txt index a6d88dd8..fe5ccbcd 100644 --- a/doc/ale-dart.txt +++ b/doc/ale-dart.txt @@ -2,6 +2,31 @@ ALE Dart Integration *ale-dart-options* +=============================================================================== +analysis_server *ale-dart-analysis_server* + +Installation +------------------------------------------------------------------------------- + +Install Dart via whatever means. `analysis_server` will be included in the SDK. + +In case that `dart` is no in your path, try to set the executable option to +its absolute path. : > + " Set the executable path for dart to the absolute path to it. + let g:ale_dart_analysis_server_executable = '/usr/local/bin/dart' +< + +Options +------------------------------------------------------------------------------- + +g:ale_dart_analysis_server_executable *g:ale_dart_analysis_server_executable* + *b:ale_dart_analysis_server_executable* + Type: |String| + Default: `'dart'` + + This variable can be set to change the path to dart. + + =============================================================================== dartanalyzer *ale-dart-dartanalyzer* -- cgit v1.2.3 From 850c41b2a9556254a883a94f3f3c74374109a77b Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Wed, 25 Mar 2020 20:36:57 +0000 Subject: Fix linting errors --- ale_linters/dart/analysis_server.vim | 1 + doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/ale_linters/dart/analysis_server.vim b/ale_linters/dart/analysis_server.vim index 4a0ea4f2..82d91334 100644 --- a/ale_linters/dart/analysis_server.vim +++ b/ale_linters/dart/analysis_server.vim @@ -14,6 +14,7 @@ endfunction function! ale_linters#dart#analysis_server#GetCommand(buffer) abort let l:executable = ale#Var(a:buffer, 'dart_analysis_server_executable') let l:dart = resolve(exepath(l:executable)) + return '%e ' \ . fnamemodify(l:dart, ':h') . '/snapshots/analysis_server.dart.snapshot' \ . ' --lsp' diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 239927be..a44ad75b 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -116,6 +116,7 @@ Notes: * Dafny * `dafny`!! * Dart + * `analysis_server` * `dartanalyzer`!! * `dartfmt`!! * `language_server` diff --git a/doc/ale.txt b/doc/ale.txt index 817201c4..d73987a9 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2664,6 +2664,7 @@ documented in additional help files. dafny...................................|ale-dafny-options| dafny.................................|ale-dafny-dafny| dart....................................|ale-dart-options| + analysis_server.......................|ale-dart-analysis_server| dartanalyzer..........................|ale-dart-dartanalyzer| dartfmt...............................|ale-dart-dartfmt| dhall...................................|ale-dhall-options| -- cgit v1.2.3 From a8acac1f4aea5fbe5bc856da6ce63881332d28d4 Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Tue, 8 Dec 2020 21:17:31 +0000 Subject: Add support for standalone files --- ale_linters/dart/analysis_server.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/dart/analysis_server.vim b/ale_linters/dart/analysis_server.vim index 82d91334..ba8839bd 100644 --- a/ale_linters/dart/analysis_server.vim +++ b/ale_linters/dart/analysis_server.vim @@ -8,7 +8,7 @@ function! ale_linters#dart#analysis_server#GetProjectRoot(buffer) abort " support for pubspec.yml let l:pubspec = ale#path#FindNearestFile(a:buffer, 'pubspec.yaml') - return !empty(l:pubspec) ? fnamemodify(l:pubspec, ':h:h') : '' + return !empty(l:pubspec) ? fnamemodify(l:pubspec, ':h:h') : '.' endfunction function! ale_linters#dart#analysis_server#GetCommand(buffer) abort -- cgit v1.2.3 From efe65f347719a34e5d60e056f2cc3dc0356af10e Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Wed, 20 Jan 2021 19:29:30 +0000 Subject: Add command callback tests --- .../test_dart_analysis_server_command_callback.vader | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/command_callback/test_dart_analysis_server_command_callback.vader diff --git a/test/command_callback/test_dart_analysis_server_command_callback.vader b/test/command_callback/test_dart_analysis_server_command_callback.vader new file mode 100644 index 00000000..1754109a --- /dev/null +++ b/test/command_callback/test_dart_analysis_server_command_callback.vader @@ -0,0 +1,15 @@ +Before: + call ale#assert#SetUpLinterTest('dart', 'analysis_server') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default command should be correct): + AssertLinter 'dart', ale#Escape('dart') + \ . ' ./snapshots/analysis_server.dart.snapshot --lsp' + +Execute(The executable should be configurable): + let g:ale_dart_analysis_server_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') + \ . ' ./snapshots/analysis_server.dart.snapshot --lsp' -- cgit v1.2.3 From 985a5295a9eaa4451ccf5616efd8262adbd06b39 Mon Sep 17 00:00:00 2001 From: Nelson Yeung Date: Wed, 20 Jan 2021 19:32:37 +0000 Subject: Fix typos --- ale_linters/dart/analysis_server.vim | 2 +- doc/ale-dart.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ale_linters/dart/analysis_server.vim b/ale_linters/dart/analysis_server.vim index ba8839bd..a6870da9 100644 --- a/ale_linters/dart/analysis_server.vim +++ b/ale_linters/dart/analysis_server.vim @@ -1,4 +1,4 @@ -" Author: Nelson Yeung +" Author: Nelson Yeung " Description: Check Dart files with dart analysis server LSP call ale#Set('dart_analysis_server_executable', 'dart') diff --git a/doc/ale-dart.txt b/doc/ale-dart.txt index fe5ccbcd..01089252 100644 --- a/doc/ale-dart.txt +++ b/doc/ale-dart.txt @@ -10,7 +10,7 @@ Installation Install Dart via whatever means. `analysis_server` will be included in the SDK. -In case that `dart` is no in your path, try to set the executable option to +In case that `dart` is not in your path, try to set the executable option to its absolute path. : > " Set the executable path for dart to the absolute path to it. let g:ale_dart_analysis_server_executable = '/usr/local/bin/dart' @@ -24,7 +24,7 @@ g:ale_dart_analysis_server_executable *g:ale_dart_analysis_server_executable* Type: |String| Default: `'dart'` - This variable can be set to change the path to dart. + This variable can be set to change the path of dart. =============================================================================== -- cgit v1.2.3