summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-03-19 20:34:11 +0000
committerGitHub <noreply@github.com>2017-03-19 20:34:11 +0000
commit51729346bfb469a03c4ddcf1cbf8c4d2588efb8c (patch)
tree56a4c672cd3f8c9feae04a788e3cb9f079371f6e
parente7d32fe37677636a0be087163c1efa7d0ba10d47 (diff)
parent297bc8553c33211e706e6b82fe819e69710d7d8b (diff)
downloadale-51729346bfb469a03c4ddcf1cbf8c4d2588efb8c.zip
Merge pull request #399 from baabelfish/master
Add support for nim check
-rw-r--r--README.md1
-rw-r--r--ale_linters/nim/nimcheck.vim55
-rw-r--r--doc/ale.txt1
-rw-r--r--test/handler/test_nim_handler.vader33
4 files changed, 90 insertions, 0 deletions
diff --git a/README.md b/README.md
index b88c7fe5..9f5c3906 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,7 @@ name. That seems to be the fairest way to arrange this table.
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/)|
| MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) |
+| Nim | [nim](https://nim-lang.org/docs/nimc.html) |
| nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) |
| nroff | [proselint](http://proselint.com/)|
| OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions
diff --git a/ale_linters/nim/nimcheck.vim b/ale_linters/nim/nimcheck.vim
new file mode 100644
index 00000000..d3e6853d
--- /dev/null
+++ b/ale_linters/nim/nimcheck.vim
@@ -0,0 +1,55 @@
+" Author: Baabelfish
+" Description: Typechecking for nim files
+
+
+function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
+ let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:buffer = l:match[1] + 0
+ let l:line = l:match[2] + 0
+ let l:column = l:match[3] + 0
+ let l:text = l:match[4]
+ let l:type = 'W'
+
+ let l:textmatch = matchlist(l:match[4], '\(.*\):')
+
+ if len(l:textmatch) > 0
+ let l:errortype = l:textmatch[1]
+ if l:errortype ==# 'Error'
+ let l:type = 'E'
+ endif
+ endif
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:line,
+ \ 'col': l:column,
+ \ 'text': l:text,
+ \ 'type': l:type,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+
+function! ale_linters#nim#nimcheck#GetCommand(buffer)
+ return 'nim check --path:' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) . ' --verbosity:0 --colors:off --listFullPaths %t'
+endfunction
+
+
+call ale#linter#Define('nim', {
+\ 'name': 'nimcheck',
+\ 'executable': 'nim',
+\ 'output_stream': 'both',
+\ 'command_callback': 'ale_linters#nim#nimcheck#GetCommand',
+\ 'callback': 'ale_linters#nim#nimcheck#Handle'
+\})
diff --git a/doc/ale.txt b/doc/ale.txt
index e4b458f7..34bf8a20 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -103,6 +103,7 @@ The following languages and tools are supported.
* Lua: 'luacheck'
* Markdown: 'mdl', 'proselint'
* MATLAB: 'mlint'
+* nim: 'nim check'
* nix: 'nix-instantiate'
* nroff: 'proselint'
* OCaml: 'merlin' (see |ale-linter-integration-ocaml-merlin|)
diff --git a/test/handler/test_nim_handler.vader b/test/handler/test_nim_handler.vader
new file mode 100644
index 00000000..d3ff8f86
--- /dev/null
+++ b/test/handler/test_nim_handler.vader
@@ -0,0 +1,33 @@
+Execute(Parsing nim errors should work):
+ runtime ale_linters/nim/nimcheck.vim
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'bufnr': 42,
+ \ 'lnum': 8,
+ \ 'col': 8,
+ \ 'text': 'Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]',
+ \ 'type': 'W',
+ \ },
+ \ {
+ \ 'bufnr': 42,
+ \ 'lnum': 12,
+ \ 'col': 2,
+ \ 'text': 'Error: identifier expected, but found ''a.barfoo''',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'bufnr': 42,
+ \ 'lnum': 2,
+ \ 'col': 5,
+ \ 'text': 'Hint: ''NotUsed'' is declared but not used [XDeclaredButNotUsed]',
+ \ 'type': 'W',
+ \ },
+ \ ],
+ \ ale_linters#nim#nimcheck#Handle(42, [
+ \ 'Line with wrong( format)',
+ \ 'foobar.nim(8, 8) Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]',
+ \ 'foobar.nim(12, 2) Error: identifier expected, but found ''a.barfoo''',
+ \ '/nested/folder/foobar.nim(2, 5) Hint: ''NotUsed'' is declared but not used [XDeclaredButNotUsed]',
+ \ ])