mirror of
https://github.com/dense-analysis/ale
synced 2024-12-30 18:12:08 +00:00
Add gitlablint support (#3042)
This commit is contained in:
parent
9e8920b336
commit
a51fd9daba
49
ale_linters/yaml/gitlablint.vim
Normal file
49
ale_linters/yaml/gitlablint.vim
Normal file
@ -0,0 +1,49 @@
|
||||
call ale#Set('yaml_gitlablint_executable', 'gll')
|
||||
call ale#Set('yaml_gitlablint_options', '')
|
||||
|
||||
function! ale_linters#yaml#gitlablint#GetCommand(buffer) abort
|
||||
return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_gitlablint_options'))
|
||||
\ . ' -p %t'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#yaml#gitlablint#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
" (<unknown>): mapping values are not allowed in this context at line 68 column 8
|
||||
" jobs:build:dev config contains unknown keys: ony
|
||||
let l:pattern = '^\(.*\) at line \(\d\+\) column \(\d\+\)$'
|
||||
let l:output = []
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if !empty(l:match)
|
||||
let l:item = {
|
||||
\ 'lnum': l:match[2] + 0,
|
||||
\ 'col': l:match[3] + 0,
|
||||
\ 'text': l:match[1],
|
||||
\ 'type': 'E',
|
||||
\}
|
||||
call add(l:output, l:item)
|
||||
else
|
||||
if l:line isnot# 'GitLab CI configuration is invalid'
|
||||
let l:item = {
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'text': l:line,
|
||||
\ 'type': 'E',
|
||||
\}
|
||||
call add(l:output, l:item)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('yaml', {
|
||||
\ 'name': 'gitlablint',
|
||||
\ 'executable': {b -> ale#Var(b, 'yaml_gitlablint_executable')},
|
||||
\ 'command': function('ale_linters#yaml#gitlablint#GetCommand'),
|
||||
\ 'callback': 'ale_linters#yaml#gitlablint#Handle',
|
||||
\ 'output_stream': 'stderr',
|
||||
\})
|
@ -665,6 +665,7 @@ Notes:
|
||||
* YAML
|
||||
* `actionlint`
|
||||
* `circleci`!!
|
||||
* `gitlablint`
|
||||
* `prettier`
|
||||
* `spectral`
|
||||
* `swaglint`
|
||||
|
@ -280,5 +280,52 @@ g:ale_yaml_yamllint_options *g:ale_yaml_yamllint_options*
|
||||
This variable can be set to pass additional options to yamllint.
|
||||
|
||||
|
||||
===============================================================================
|
||||
gitlablint *ale-yaml-gitlablint*
|
||||
|
||||
Website: https://github.com/elijah-roberts/gitlab-lint
|
||||
|
||||
|
||||
Installation
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Install yamllint in your a virtualenv directory, locally, or globally: >
|
||||
|
||||
pip3 install gitlab_lint # After activating virtualenv
|
||||
pip3 install --user gitlab_lint # Install to ~/.local/bin
|
||||
sudo pip3 install gitlab_lint # Install globally
|
||||
|
||||
See |g:ale_virtualenv_dir_names| for configuring how ALE searches for
|
||||
virtualenv directories.
|
||||
|
||||
Is recommended to use |g:ale_pattern_options| to enable this linter so it only
|
||||
applies to 'gitlab-ci.yml' files and not all yaml files:
|
||||
>
|
||||
let g:ale_pattern_options = {
|
||||
\ '.gitlab-ci\.yml$': {
|
||||
\ 'ale_linters': ['gitlablint'],
|
||||
\ },
|
||||
\}
|
||||
<
|
||||
|
||||
Options
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
g:ale_yaml_gitlablint_executable *g:ale_yaml_gitlablint_executable*
|
||||
*b:ale_yaml_gitlablint_executable*
|
||||
Type: |String|
|
||||
Default: `'gll'`
|
||||
|
||||
This variable can be set to change the path to gll.
|
||||
|
||||
|
||||
g:ale_yaml_gitlablint_options *g:ale_yaml_gitlablint_options*
|
||||
*b:ale_yaml_gitlablint_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to gll.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
@ -3329,6 +3329,7 @@ documented in additional help files.
|
||||
yaml-language-server..................|ale-yaml-language-server|
|
||||
yamlfix...............................|ale-yaml-yamlfix|
|
||||
yamllint..............................|ale-yaml-yamllint|
|
||||
gitlablint............................|ale-yaml-gitlablint|
|
||||
yang....................................|ale-yang-options|
|
||||
yang-lsp..............................|ale-yang-lsp|
|
||||
zeek....................................|ale-zeek-options|
|
||||
|
@ -674,6 +674,7 @@ formatting.
|
||||
* YAML
|
||||
* [actionlint](https://github.com/rhysd/actionlint) :warning:
|
||||
* [circleci](https://circleci.com/docs/2.0/local-cli) :floppy_disk: :warning:
|
||||
* [gitlablint](https://github.com/elijah-roberts/gitlab-lint)
|
||||
* [prettier](https://github.com/prettier/prettier)
|
||||
* [spectral](https://github.com/stoplightio/spectral)
|
||||
* [swaglint](https://github.com/byCedric/swaglint) :warning:
|
||||
|
35
test/handler/test_gitlablint_handler.vader
Normal file
35
test/handler/test_gitlablint_handler.vader
Normal file
@ -0,0 +1,35 @@
|
||||
Before:
|
||||
runtime! ale_linters/yaml/gitlablint.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(Problems should be parsed correctly for gitlablint):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'root config contains unknown keys: efore_script',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 77,
|
||||
\ 'col': 3,
|
||||
\ 'type': 'E',
|
||||
\ 'text': '(<unknown>): could not find expected : while scanning a simple key',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'build:dev:rest job: undefined need: chck:dev',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#yaml#gitlablint#Handle(bufnr(''), [
|
||||
\ 'GitLab CI configuration is invalid',
|
||||
\ 'root config contains unknown keys: efore_script',
|
||||
\ '(<unknown>): could not find expected : while scanning a simple key at line 77 column 3',
|
||||
\ 'build:dev:rest job: undefined need: chck:dev',
|
||||
\ ])
|
Loading…
Reference in New Issue
Block a user