Fix 2777 - Add IBM openapi validator
This commit is contained in:
parent
a1e6df987c
commit
03eae9e085
7 changed files with 170 additions and 0 deletions
58
ale_linters/openapi/ibm_validator.vim
Normal file
58
ale_linters/openapi/ibm_validator.vim
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
" Author: Horacio Sanson <hsanson@gmail.com>
|
||||||
|
|
||||||
|
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',
|
||||||
|
\})
|
42
doc/ale-openapi.txt
Normal file
42
doc/ale-openapi.txt
Normal file
|
@ -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:
|
|
@ -322,6 +322,8 @@ Notes:
|
||||||
* `ocamlformat`
|
* `ocamlformat`
|
||||||
* `ocp-indent`
|
* `ocp-indent`
|
||||||
* `ols`
|
* `ols`
|
||||||
|
* OpenApi
|
||||||
|
* `ibm-validator`
|
||||||
* Pawn
|
* Pawn
|
||||||
* `uncrustify`
|
* `uncrustify`
|
||||||
* Perl
|
* Perl
|
||||||
|
|
|
@ -2835,6 +2835,8 @@ documented in additional help files.
|
||||||
ols...................................|ale-ocaml-ols|
|
ols...................................|ale-ocaml-ols|
|
||||||
ocamlformat...........................|ale-ocaml-ocamlformat|
|
ocamlformat...........................|ale-ocaml-ocamlformat|
|
||||||
ocp-indent............................|ale-ocaml-ocp-indent|
|
ocp-indent............................|ale-ocaml-ocp-indent|
|
||||||
|
openapi.................................|ale-openapi-options|
|
||||||
|
ibm-validator.........................|ale-openapi-ibm-validator|
|
||||||
pawn....................................|ale-pawn-options|
|
pawn....................................|ale-pawn-options|
|
||||||
uncrustify............................|ale-pawn-uncrustify|
|
uncrustify............................|ale-pawn-uncrustify|
|
||||||
perl....................................|ale-perl-options|
|
perl....................................|ale-perl-options|
|
||||||
|
|
|
@ -331,6 +331,8 @@ formatting.
|
||||||
* [ocamlformat](https://github.com/ocaml-ppx/ocamlformat)
|
* [ocamlformat](https://github.com/ocaml-ppx/ocamlformat)
|
||||||
* [ocp-indent](https://github.com/OCamlPro/ocp-indent)
|
* [ocp-indent](https://github.com/OCamlPro/ocp-indent)
|
||||||
* [ols](https://github.com/freebroccolo/ocaml-language-server)
|
* [ols](https://github.com/freebroccolo/ocaml-language-server)
|
||||||
|
* OpenApi
|
||||||
|
* [ibm-validator](https://github.com/IBM/openapi-validator)
|
||||||
* Pawn
|
* Pawn
|
||||||
* [uncrustify](https://github.com/uncrustify/uncrustify)
|
* [uncrustify](https://github.com/uncrustify/uncrustify)
|
||||||
* Perl
|
* Perl
|
||||||
|
|
|
@ -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'
|
49
test/handler/test_ibm_openapi_validator_handler.vader
Normal file
49
test/handler/test_ibm_openapi_validator_handler.vader
Normal file
|
@ -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'
|
||||||
|
\ ])
|
Reference in a new issue