summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/yaml/circleci.vim35
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale-yaml.txt26
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/handler/test_circleci_handler.vader39
-rw-r--r--test/linter/test_circleci.vader13
-rw-r--r--test/test-files/.circleci/config.yml0
8 files changed, 116 insertions, 0 deletions
diff --git a/ale_linters/yaml/circleci.vim b/ale_linters/yaml/circleci.vim
new file mode 100644
index 00000000..3df61459
--- /dev/null
+++ b/ale_linters/yaml/circleci.vim
@@ -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,
+\})
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 67dc971c..4a901488 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -568,6 +568,7 @@ Notes:
* XML
* `xmllint`
* YAML
+ * `circleci`!!
* `prettier`
* `spectral`
* `swaglint`
diff --git a/doc/ale-yaml.txt b/doc/ale-yaml.txt
index 04871403..65e0d069 100644
--- a/doc/ale-yaml.txt
+++ b/doc/ale-yaml.txt
@@ -1,6 +1,28 @@
===============================================================================
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*
@@ -15,11 +37,13 @@ Install prettier either globally or locally: >
npm install prettier -g # global
npm install prettier # local
<
+
===============================================================================
spectral *ale-yaml-spectral*
Website: https://github.com/stoplightio/spectral
+
Installation
-------------------------------------------------------------------------------
@@ -80,6 +104,7 @@ g:ale_yaml_swaglint_use_global *g:ale_yaml_swaglint_use_global*
See |ale-integrations-local-executables|
+
===============================================================================
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|
+
===============================================================================
yamllint *ale-yaml-yamllint*
diff --git a/doc/ale.txt b/doc/ale.txt
index b7059af9..9ff05059 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3083,6 +3083,7 @@ documented in additional help files.
xml.....................................|ale-xml-options|
xmllint...............................|ale-xml-xmllint|
yaml....................................|ale-yaml-options|
+ circleci..............................|ale-yaml-circleci|
prettier..............................|ale-yaml-prettier|
spectral..............................|ale-yaml-spectral|
swaglint..............................|ale-yaml-swaglint|
diff --git a/supported-tools.md b/supported-tools.md
index 0f33006b..7848d111 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -577,6 +577,7 @@ formatting.
* XML
* [xmllint](http://xmlsoft.org/xmllint.html)
* YAML
+ * [circleci](https://circleci.com/docs/2.0/local-cli) :floppy_disk:
* [prettier](https://github.com/prettier/prettier)
* [spectral](https://github.com/stoplightio/spectral)
* [swaglint](https://github.com/byCedric/swaglint)
diff --git a/test/handler/test_circleci_handler.vader b/test/handler/test_circleci_handler.vader
new file mode 100644
index 00000000..8ffba360
--- /dev/null
+++ b/test/handler/test_circleci_handler.vader
@@ -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',
+ \ ])
diff --git a/test/linter/test_circleci.vader b/test/linter/test_circleci.vader
new file mode 100644
index 00000000..f63cc513
--- /dev/null
+++ b/test/linter/test_circleci.vader
@@ -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'
diff --git a/test/test-files/.circleci/config.yml b/test/test-files/.circleci/config.yml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/.circleci/config.yml