summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-04-15 21:09:23 +0100
committerGitHub <noreply@github.com>2017-04-15 21:09:23 +0100
commit35c831dd2c9c5316d64aebc7df9fae9765af716c (patch)
treec5e308223badfec889422833354cd20779c082c5 /ale_linters
parent296ae92da4c85f7bb607ec39f431bc1bdd5eeab4 (diff)
parentf0d76bc298778789072b87b73789141c750f1f50 (diff)
downloadale-35c831dd2c9c5316d64aebc7df9fae9765af716c.zip
Merge pull request #471 from breed808/gometalinter
Add gometalinter linter for go files
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/go/gometalinter.vim56
1 files changed, 56 insertions, 0 deletions
diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim
new file mode 100644
index 00000000..8dbd8b26
--- /dev/null
+++ b/ale_linters/go/gometalinter.vim
@@ -0,0 +1,56 @@
+" Author: Ben Reedy <https://github.com/breed808>
+" Description: Adds support for the gometalinter suite for Go files
+
+if !exists('g:ale_go_gometalinter_options')
+ let g:ale_go_gometalinter_options = ''
+endif
+
+function! ale_linters#go#gometalinter#GetCommand(buffer) abort
+ return 'gometalinter '
+ \ . g:ale_go_gometalinter_options
+ \ . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+endfunction
+
+function! ale_linters#go#gometalinter#Handler(buffer, lines) abort
+ " Matches patterns line the following:
+ "
+ " file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args
+ " file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
+ " file.go:5:2: expected declaration, found 'STRING' "log"
+
+ " gometalinter returns relative paths so use tail of filename as part of pattern matcher
+ let l:filename = fnamemodify(bufname(a:buffer), ':t')
+ let l:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
+ let l:pattern = '^' . l:path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\?:\?\(warning\|error\):\?\s\*\?\(.\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ " Omit errors from files other than the one currently open
+ if len(l:match) == 0 || l:line !~ l:filename
+ continue
+ endif
+
+ " vcol is Needed to indicate that the column is a character.
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[4],
+ \ 'type': tolower(l:match[3]) ==# 'warning' ? 'W' : 'E',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('go', {
+\ 'name': 'gometalinter',
+\ 'executable': 'gometalinter',
+\ 'command_callback': 'ale_linters#go#gometalinter#GetCommand',
+\ 'callback': 'ale_linters#go#gometalinter#Handler',
+\ 'lint_file': 1,
+\})