From 297bc8553c33211e706e6b82fe819e69710d7d8b Mon Sep 17 00:00:00 2001 From: baabelfish Date: Sat, 18 Mar 2017 18:33:26 +0200 Subject: [PATCH] Add support for nim check --- README.md | 1 + ale_linters/nim/nimcheck.vim | 55 +++++++++++++++++++++++++++++ doc/ale.txt | 1 + test/handler/test_nim_handler.vader | 33 +++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 ale_linters/nim/nimcheck.vim create mode 100644 test/handler/test_nim_handler.vader 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]', + \ ])