summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/openapi/ibm_validator.vim58
-rw-r--r--doc/ale-openapi.txt42
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md2
-rw-r--r--test/command_callback/test_ibm_openapi_validator_command_callback.vader15
-rw-r--r--test/handler/test_ibm_openapi_validator_handler.vader49
7 files changed, 170 insertions, 0 deletions
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 <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',
+\})
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'
+ \ ])