Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nimcheck end_col options #2887

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ale_linters/nim/nimcheck.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
" Author: Baabelfish
" Description: Typechecking for nim files

let s:end_col_patterns = [
\ '\v''([^'']+)'' is declared but not used.*',
\ '\videntifier expected, but found ''([^'']+)''',
\ '\vimported and not used: ''([^'']+)''.*',
\ '\vundeclared identifier: ''([^'']+)''',
\ '\v''([^'']+)'' cannot be assigned to',
\ '\vredefinition of ''([^'']+)'';',
\]

function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
Expand Down Expand Up @@ -43,6 +52,11 @@ function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
let l:item.code = l:code_match[2]
endif

" Find position end_col.
for l:col_match in ale#util#GetMatches(l:item.text, s:end_col_patterns)
let l:item.end_col = l:item.col + len(l:col_match[1]) - 1
endfor

call add(l:output, l:item)
endfor

Expand Down
35 changes: 35 additions & 0 deletions test/handler/test_nim_handler.vader
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,60 @@ Execute(Parsing nim errors should work):
\ 'col': 2,
\ 'text': 'identifier expected, but found ''a.barfoo''',
\ 'type': 'E',
\ 'end_col': 9,
\ },
\ {
\ 'lnum': 2,
\ 'col': 5,
\ 'text': '''NotUsed'' is declared but not used',
\ 'code': 'XDeclaredButNotUsed',
\ 'type': 'W',
\ 'end_col': 11,
\ },
\ {
\ 'lnum': 12,
\ 'col': 2,
\ 'text': 'with : character',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 1,
\ 'col': 8,
\ 'text': 'imported and not used: ''strutils''',
\ 'code': 'UnusedImport',
\ 'type': 'W',
\ 'end_col': 15,
\ },
\ {
\ 'lnum': 12,
\ 'col': 9,
\ 'text': 'undeclared identifier: ''total''',
\ 'type': 'E',
\ 'end_col': 13,
\ },
\ {
\ 'lnum': 14,
\ 'col': 1,
\ 'text': '''sum'' cannot be assigned to',
\ 'type': 'E',
\ 'end_col': 3,
\ },
\ {
\ 'lnum': 15,
\ 'col': 1,
\ 'text': 'redefinition of ''getName''; previous declaration here: /nested/folder/foobar.nim(14, 6)',
\ 'type': 'E',
\ 'end_col': 7,
\ },
\ ],
\ ale_linters#nim#nimcheck#Handle(bufnr(''), [
\ '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]',
\ 'foobar.nim(12, 2) Error: with : character',
\ 'foobar.nim(1, 8) Warning: imported and not used: ''strutils'' [UnusedImport]',
\ 'foobar.nim(12, 9) Error: undeclared identifier: ''total''',
\ 'foobar.nim(14, 1) Error: ''sum'' cannot be assigned to',
\ 'foobar.nim(15, 1) Error: redefinition of ''getName''; previous declaration here: /nested/folder/foobar.nim(14, 6)',
\ ])