mirror of
https://github.com/dense-analysis/ale
synced 2024-12-17 11:55:24 +00:00
Merge pull request #399 from baabelfish/master
Add support for nim check
This commit is contained in:
commit
51729346bf
@ -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
|
||||
|
55
ale_linters/nim/nimcheck.vim
Normal file
55
ale_linters/nim/nimcheck.vim
Normal file
@ -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'
|
||||
\})
|
@ -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|)
|
||||
|
33
test/handler/test_nim_handler.vader
Normal file
33
test/handler/test_nim_handler.vader
Normal file
@ -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]',
|
||||
\ ])
|
Loading…
Reference in New Issue
Block a user