diff options
-rw-r--r-- | ale_linters/yaml/gitlablint.vim | 49 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale-yaml.txt | 47 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/handler/test_gitlablint_handler.vader | 35 |
6 files changed, 134 insertions, 0 deletions
diff --git a/ale_linters/yaml/gitlablint.vim b/ale_linters/yaml/gitlablint.vim new file mode 100644 index 00000000..ec48115a --- /dev/null +++ b/ale_linters/yaml/gitlablint.vim @@ -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', +\}) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 4f90ecb6..c7548f9f 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -665,6 +665,7 @@ Notes: * YAML * `actionlint` * `circleci`!! + * `gitlablint` * `prettier` * `spectral` * `swaglint` diff --git a/doc/ale-yaml.txt b/doc/ale-yaml.txt index 9733990e..b3450b87 100644 --- a/doc/ale-yaml.txt +++ b/doc/ale-yaml.txt @@ -281,4 +281,51 @@ g:ale_yaml_yamllint_options *g:ale_yaml_yamllint_options* =============================================================================== +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: diff --git a/doc/ale.txt b/doc/ale.txt index 049f7159..ed3696d4 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/supported-tools.md b/supported-tools.md index 61f16b09..70896ca9 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -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: diff --git a/test/handler/test_gitlablint_handler.vader b/test/handler/test_gitlablint_handler.vader new file mode 100644 index 00000000..3b08ccb4 --- /dev/null +++ b/test/handler/test_gitlablint_handler.vader @@ -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', + \ ]) |