Add yamllint and prettier to openapi.

This commit enables yamllint and prettier on openapi files.
This commit is contained in:
Horacio Sanson 2019-10-27 00:16:23 +09:00 committed by Horacio Sanson
parent 03eae9e085
commit 014b00d4d7
10 changed files with 74 additions and 46 deletions

View file

@ -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',
\})

View file

@ -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 '<stream end>'
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',
\})

View file

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

View file

@ -83,6 +83,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
\ 'markdown': 'markdown',
\ 'vue': 'vue',
\ 'yaml': 'yaml',
\ 'openapi': 'yaml',
\ 'html': 'html',
\}

View file

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

View file

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

View file

@ -324,6 +324,8 @@ Notes:
* `ols`
* OpenApi
* `ibm-validator`
* `prettier`
* `yamllint`
* Pawn
* `uncrustify`
* Perl

View file

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

View file

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

View file

@ -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 ''<stream end>''',
\ },
\ ],
\ 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 ''<stream end>''',
\ ])
@ -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)',
\ ])