Fix 2777 - Add IBM openapi validator

This commit is contained in:
Horacio Sanson 2019-09-20 22:04:44 +09:00 committed by Horacio Sanson
parent a1e6df987c
commit 03eae9e085
7 changed files with 170 additions and 0 deletions

View 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
View 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:

View File

@ -322,6 +322,8 @@ Notes:
* `ocamlformat`
* `ocp-indent`
* `ols`
* OpenApi
* `ibm-validator`
* Pawn
* `uncrustify`
* Perl

View File

@ -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|

View File

@ -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

View File

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

View 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'
\ ])