summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShogo NAMEKI <nametake.kyarabuki@gmail.com>2017-11-20 19:57:13 +0900
committerw0rp <w0rp@users.noreply.github.com>2017-11-20 10:57:13 +0000
commitf20e5a4cf0e56c3c89ef7be4730924be377e5f61 (patch)
tree71abbae0f375fca62cf335f2cfc95b80aa2f31c3
parentf224ce8a377bbb3a0deb78b98fdc6c43555791e2 (diff)
downloadale-f20e5a4cf0e56c3c89ef7be4730924be377e5f61.zip
Add `drafter` for checking API Blueprint files (#1152)
-rw-r--r--README.md1
-rw-r--r--ale_linters/apiblueprint/drafter.vim36
-rw-r--r--doc/ale.txt1
-rw-r--r--test/handler/test_drafter_handler.vader37
4 files changed, 75 insertions, 0 deletions
diff --git a/README.md b/README.md
index 6ed4b1d2..73827899 100644
--- a/README.md
+++ b/README.md
@@ -74,6 +74,7 @@ formatting.
| -------- | ----- |
| ASM | [gcc](https://gcc.gnu.org) |
| Ansible | [ansible-lint](https://github.com/willthames/ansible-lint) |
+| API Blueprint | [drafter](https://github.com/apiaryio/drafter) |
| AsciiDoc | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good), [redpen](http://redpen.cc/)|
| Awk | [gawk](https://www.gnu.org/software/gawk/)|
| Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
diff --git a/ale_linters/apiblueprint/drafter.vim b/ale_linters/apiblueprint/drafter.vim
new file mode 100644
index 00000000..9cded359
--- /dev/null
+++ b/ale_linters/apiblueprint/drafter.vim
@@ -0,0 +1,36 @@
+" Author: nametake https://nametake.github.io
+" Description: apiblueprint parser
+
+function! ale_linters#apiblueprint#drafter#HandleErrors(buffer, lines) abort
+ " Matches patterns line the following:
+ "
+ " warning: (3) unable to parse response signature, expected 'response [<HTTP status code>] [(<media type>)]'; line 4, column 3k - line 4, column 22
+ " warning: (10) message-body asset is expected to be a pre-formatted code block, separate it by a newline and indent every of its line by 12 spaces or 3 tabs; line 30, column 5 - line 30, column 9; line 31, column 9 - line 31, column 14; line 32, column 9 - line 32, column 14
+ let l:pattern = '\(^.*\): (\d\+) \(.\{-\}\); line \(\d\+\), column \(\d\+\) - line \d\+, column \d\+\(.*; line \d\+, column \d\+ - line \(\d\+\), column \(\d\+\)\)\{-\}$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines[2:], l:pattern)
+ let l:item = {
+ \ 'type': l:match[1] is# 'warning' ? 'W' : 'E',
+ \ 'text': l:match[2],
+ \ 'lnum': l:match[3] + 0,
+ \ 'col': l:match[4] + 0,
+ \}
+ if l:match[5] isnot# ''
+ let l:item.end_lnum = l:match[6] + 0
+ let l:item.end_col = l:match[7] + 0
+ endif
+ call add(l:output, l:item)
+ endfor
+
+ return l:output
+endfunction
+
+
+call ale#linter#Define('apiblueprint', {
+\ 'name': 'drafter',
+\ 'output_stream': 'stderr',
+\ 'executable': 'drafter',
+\ 'command': 'drafter --use-line-num --validate %t',
+\ 'callback': 'ale_linters#apiblueprint#drafter#HandleErrors',
+\})
diff --git a/doc/ale.txt b/doc/ale.txt
index 223f16c9..63991113 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -264,6 +264,7 @@ Notes:
* ASM: `gcc`
* Ansible: `ansible-lint`
+* API Blueprint: `drafter`
* AsciiDoc: `proselint`, `write-good`, `redpen`
* Awk: `gawk`
* Bash: `shell` (-n flag), `shellcheck`, `shfmt`
diff --git a/test/handler/test_drafter_handler.vader b/test/handler/test_drafter_handler.vader
new file mode 100644
index 00000000..1524dde1
--- /dev/null
+++ b/test/handler/test_drafter_handler.vader
@@ -0,0 +1,37 @@
+Before:
+ runtime! ale_linters/apiblueprint/drafter.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(drafter handler should handle errors output):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 25,
+ \ 'col': 3,
+ \ 'text': "unable to parse response signature, expected 'response [<HTTP status code>] [(<media type>)]'",
+ \ 'type': "W",
+ \ },
+ \ {
+ \ 'lnum': 25,
+ \ 'col': 3,
+ \ 'text': "missing response HTTP status code, assuming 'Response 200'",
+ \ 'type': "W",
+ \ },
+ \ {
+ \ 'lnum': 30,
+ \ 'col': 7,
+ \ 'end_lnum': 32,
+ \ 'end_col': 7,
+ \ 'text': "message-body asset is expected to be a pre-formatted code block, separate it by a newline and indent every of its line by 12 spaces or 3 tabs",
+ \ 'type': "W",
+ \ },
+ \ ],
+ \ ale_linters#apiblueprint#drafter#HandleErrors(bufnr(''), [
+ \ "",
+ \ "OK.",
+ \ "warning: (3) unable to parse response signature, expected 'response [<HTTP status code>] [(<media type>)]'; line 25, column 3 - line 25, column 29",
+ \ "warning: (6) missing response HTTP status code, assuming 'Response 200'; line 25, column 3 - line 25, column 29",
+ \ "warning: (10) message-body asset is expected to be a pre-formatted code block, separate it by a newline and indent every of its line by 12 spaces or 3 tabs; line 30, column 7 - line 30, column 11; line 31, column 6 - line 31, column 7; line 32, column 6 - line 32, column 7"
+ \ ])