mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-10 22:41:52 +08:00
Close #3770 - Add support for checking circleci configs
This commit is contained in:
35
ale_linters/yaml/circleci.vim
Normal file
35
ale_linters/yaml/circleci.vim
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
function! ale_linters#yaml#circleci#Handle(buffer, lines) abort
|
||||||
|
let l:match_index = -1
|
||||||
|
let l:output = []
|
||||||
|
|
||||||
|
for l:index in range(len(a:lines))
|
||||||
|
let l:line = a:lines[l:index]
|
||||||
|
|
||||||
|
if l:line =~? 'Error: ERROR IN CONFIG FILE:'
|
||||||
|
let l:match_index = l:index + 1
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
if l:match_index > 0
|
||||||
|
return [{
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'text': a:lines[l:match_index],
|
||||||
|
\ 'detail': join(a:lines[l:match_index :], "\n"),
|
||||||
|
\}]
|
||||||
|
endif
|
||||||
|
|
||||||
|
return []
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" The circleci validate requires network requests, so we'll only run it when
|
||||||
|
" files are saved to prevent the server from being hammered.
|
||||||
|
call ale#linter#Define('yaml', {
|
||||||
|
\ 'name': 'circleci',
|
||||||
|
\ 'executable': {b -> expand('#' . b . ':p') =~? '\.circleci' ? 'circleci' : ''},
|
||||||
|
\ 'command': 'circleci config validate - < %s',
|
||||||
|
\ 'callback': 'ale_linters#yaml#circleci#Handle',
|
||||||
|
\ 'output_stream': 'stderr',
|
||||||
|
\ 'lint_file': 1,
|
||||||
|
\})
|
||||||
@@ -568,6 +568,7 @@ Notes:
|
|||||||
* XML
|
* XML
|
||||||
* `xmllint`
|
* `xmllint`
|
||||||
* YAML
|
* YAML
|
||||||
|
* `circleci`!!
|
||||||
* `prettier`
|
* `prettier`
|
||||||
* `spectral`
|
* `spectral`
|
||||||
* `swaglint`
|
* `swaglint`
|
||||||
|
|||||||
@@ -1,6 +1,28 @@
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
ALE YAML Integration *ale-yaml-options*
|
ALE YAML Integration *ale-yaml-options*
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
circleci *ale-yaml-circleci*
|
||||||
|
|
||||||
|
Website: https://circleci.com/docs/2.0/local-cli
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Follow the instructions on the website, and make sure to test that you can
|
||||||
|
validate configuration files with: >
|
||||||
|
|
||||||
|
circleci config validate - < .circleci/config.yml
|
||||||
|
<
|
||||||
|
|
||||||
|
As long as the validator runs correctly, you should be able to see errors when
|
||||||
|
you save the configuration file. The validator doesn't run as you type because
|
||||||
|
it sends network requests, and running too often would overload the circleci
|
||||||
|
servers.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
prettier *ale-yaml-prettier*
|
prettier *ale-yaml-prettier*
|
||||||
|
|
||||||
@@ -15,11 +37,13 @@ Install prettier either globally or locally: >
|
|||||||
npm install prettier -g # global
|
npm install prettier -g # global
|
||||||
npm install prettier # local
|
npm install prettier # local
|
||||||
<
|
<
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
spectral *ale-yaml-spectral*
|
spectral *ale-yaml-spectral*
|
||||||
|
|
||||||
Website: https://github.com/stoplightio/spectral
|
Website: https://github.com/stoplightio/spectral
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -80,6 +104,7 @@ g:ale_yaml_swaglint_use_global *g:ale_yaml_swaglint_use_global*
|
|||||||
|
|
||||||
See |ale-integrations-local-executables|
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
yamlfix *ale-yaml-yamlfix*
|
yamlfix *ale-yaml-yamlfix*
|
||||||
|
|
||||||
@@ -118,6 +143,7 @@ g:ale_yaml_yamlfix_use_global *g:ale_yaml_yamlfix_use_global*
|
|||||||
|
|
||||||
See |ale-integrations-local-executables|
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
yamllint *ale-yaml-yamllint*
|
yamllint *ale-yaml-yamllint*
|
||||||
|
|
||||||
|
|||||||
@@ -3083,6 +3083,7 @@ documented in additional help files.
|
|||||||
xml.....................................|ale-xml-options|
|
xml.....................................|ale-xml-options|
|
||||||
xmllint...............................|ale-xml-xmllint|
|
xmllint...............................|ale-xml-xmllint|
|
||||||
yaml....................................|ale-yaml-options|
|
yaml....................................|ale-yaml-options|
|
||||||
|
circleci..............................|ale-yaml-circleci|
|
||||||
prettier..............................|ale-yaml-prettier|
|
prettier..............................|ale-yaml-prettier|
|
||||||
spectral..............................|ale-yaml-spectral|
|
spectral..............................|ale-yaml-spectral|
|
||||||
swaglint..............................|ale-yaml-swaglint|
|
swaglint..............................|ale-yaml-swaglint|
|
||||||
|
|||||||
@@ -577,6 +577,7 @@ formatting.
|
|||||||
* XML
|
* XML
|
||||||
* [xmllint](http://xmlsoft.org/xmllint.html)
|
* [xmllint](http://xmlsoft.org/xmllint.html)
|
||||||
* YAML
|
* YAML
|
||||||
|
* [circleci](https://circleci.com/docs/2.0/local-cli) :floppy_disk:
|
||||||
* [prettier](https://github.com/prettier/prettier)
|
* [prettier](https://github.com/prettier/prettier)
|
||||||
* [spectral](https://github.com/stoplightio/spectral)
|
* [spectral](https://github.com/stoplightio/spectral)
|
||||||
* [swaglint](https://github.com/byCedric/swaglint)
|
* [swaglint](https://github.com/byCedric/swaglint)
|
||||||
|
|||||||
39
test/handler/test_circleci_handler.vader
Normal file
39
test/handler/test_circleci_handler.vader
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
Before:
|
||||||
|
runtime ale_linters/yaml/circleci.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(The circlei handler should return nothing when configs are valid):
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#yaml#circleci#Handle(0, [
|
||||||
|
\ 'Config input is valid.',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(The circlei handler put errors at the top when something is wrong):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': '[#/jobs] expected type: Mapping, found: Integer',
|
||||||
|
\ 'detail': join([
|
||||||
|
\ '[#/jobs] expected type: Mapping, found: Integer',
|
||||||
|
\ 'Jobs is a map',
|
||||||
|
\ 'SCHEMA:',
|
||||||
|
\ ' type: object',
|
||||||
|
\ 'INPUT:',
|
||||||
|
\ ' 4',
|
||||||
|
\ ], "\n"),
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#yaml#circleci#Handle(0, [
|
||||||
|
\ 'Error: ERROR IN CONFIG FILE:',
|
||||||
|
\ '[#/jobs] expected type: Mapping, found: Integer',
|
||||||
|
\ 'Jobs is a map',
|
||||||
|
\ 'SCHEMA:',
|
||||||
|
\ ' type: object',
|
||||||
|
\ 'INPUT:',
|
||||||
|
\ ' 4',
|
||||||
|
\ ])
|
||||||
13
test/linter/test_circleci.vader
Normal file
13
test/linter/test_circleci.vader
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('yaml', 'circleci')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The linter should not run for every YAML file):
|
||||||
|
AssertLinterNotExecuted
|
||||||
|
|
||||||
|
Execute(The linter should for YAML files in a .circleci directory):
|
||||||
|
call ale#test#SetFilename('../test-files/.circleci/config.yml')
|
||||||
|
|
||||||
|
AssertLinter 'circleci', 'circleci config validate - < %s'
|
||||||
0
test/test-files/.circleci/config.yml
Normal file
0
test/test-files/.circleci/config.yml
Normal file
Reference in New Issue
Block a user