mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
Add yamllint and prettier to openapi.
This commit enables yamllint and prettier on openapi files.
This commit is contained in:
committed by
Horacio Sanson
parent
03eae9e085
commit
014b00d4d7
9
ale_linters/openapi/yamllint.vim
Normal file
9
ale_linters/openapi/yamllint.vim
Normal 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',
|
||||||
|
\})
|
||||||
@@ -3,48 +3,9 @@
|
|||||||
call ale#Set('yaml_yamllint_executable', 'yamllint')
|
call ale#Set('yaml_yamllint_executable', 'yamllint')
|
||||||
call ale#Set('yaml_yamllint_options', '')
|
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', {
|
call ale#linter#Define('yaml', {
|
||||||
\ 'name': 'yamllint',
|
\ 'name': 'yamllint',
|
||||||
\ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')},
|
\ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')},
|
||||||
\ 'command': function('ale_linters#yaml#yamllint#GetCommand'),
|
\ 'command': function('ale#handlers#yamllint#GetCommand'),
|
||||||
\ 'callback': 'ale_linters#yaml#yamllint#Handle',
|
\ 'callback': 'ale#handlers#yamllint#Handle',
|
||||||
\})
|
\})
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ let s:default_registry = {
|
|||||||
\ },
|
\ },
|
||||||
\ 'prettier': {
|
\ 'prettier': {
|
||||||
\ 'function': 'ale#fixers#prettier#Fix',
|
\ '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.',
|
\ 'description': 'Apply prettier to a file.',
|
||||||
\ },
|
\ },
|
||||||
\ 'prettier_eslint': {
|
\ 'prettier_eslint': {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
|
|||||||
\ 'markdown': 'markdown',
|
\ 'markdown': 'markdown',
|
||||||
\ 'vue': 'vue',
|
\ 'vue': 'vue',
|
||||||
\ 'yaml': 'yaml',
|
\ 'yaml': 'yaml',
|
||||||
|
\ 'openapi': 'yaml',
|
||||||
\ 'html': 'html',
|
\ 'html': 'html',
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
|||||||
39
autoload/ale/handlers/yamllint.vim
Normal file
39
autoload/ale/handlers/yamllint.vim
Normal 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
|
||||||
|
|
||||||
@@ -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.
|
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:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|||||||
@@ -324,6 +324,8 @@ Notes:
|
|||||||
* `ols`
|
* `ols`
|
||||||
* OpenApi
|
* OpenApi
|
||||||
* `ibm-validator`
|
* `ibm-validator`
|
||||||
|
* `prettier`
|
||||||
|
* `yamllint`
|
||||||
* Pawn
|
* Pawn
|
||||||
* `uncrustify`
|
* `uncrustify`
|
||||||
* Perl
|
* Perl
|
||||||
|
|||||||
@@ -2837,6 +2837,8 @@ documented in additional help files.
|
|||||||
ocp-indent............................|ale-ocaml-ocp-indent|
|
ocp-indent............................|ale-ocaml-ocp-indent|
|
||||||
openapi.................................|ale-openapi-options|
|
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|
|
pawn....................................|ale-pawn-options|
|
||||||
uncrustify............................|ale-pawn-uncrustify|
|
uncrustify............................|ale-pawn-uncrustify|
|
||||||
perl....................................|ale-perl-options|
|
perl....................................|ale-perl-options|
|
||||||
|
|||||||
@@ -333,6 +333,8 @@ formatting.
|
|||||||
* [ols](https://github.com/freebroccolo/ocaml-language-server)
|
* [ols](https://github.com/freebroccolo/ocaml-language-server)
|
||||||
* OpenApi
|
* 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
|
* Pawn
|
||||||
* [uncrustify](https://github.com/uncrustify/uncrustify)
|
* [uncrustify](https://github.com/uncrustify/uncrustify)
|
||||||
* Perl
|
* Perl
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Before:
|
|||||||
|
|
||||||
let g:ale_warn_about_trailing_whitespace = 1
|
let g:ale_warn_about_trailing_whitespace = 1
|
||||||
|
|
||||||
runtime! ale_linters/yaml/yamllint.vim
|
runtime! ale/handlers/yamllint.vim
|
||||||
|
|
||||||
After:
|
After:
|
||||||
Restore
|
Restore
|
||||||
@@ -29,7 +29,7 @@ Execute(Problems should be parsed correctly for yamllint):
|
|||||||
\ 'text': 'syntax error: expected the node content, but found ''<stream end>''',
|
\ '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.yaml:1:1: [warning] missing document start "---" (document-start)',
|
||||||
\ 'something.yml:2:1: [error] syntax error: expected the node content, but found ''<stream end>''',
|
\ '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',
|
\ 'code': 'trailing-spaces',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#yaml#yamllint#Handle(bufnr(''), [
|
\ ale#handlers#yamllint#Handle(bufnr(''), [
|
||||||
\ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)',
|
\ '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
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#yaml#yamllint#Handle(bufnr(''), [
|
\ ale#handlers#yamllint#Handle(bufnr(''), [
|
||||||
\ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)',
|
\ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)',
|
||||||
\ ])
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user