summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Reedy <breed808@breed808.com>2017-04-13 19:25:35 +1000
committerBen Reedy <breed808@breed808.com>2017-04-13 19:38:32 +1000
commit1167616726f9e995da9ac5b674cf6ded2d221855 (patch)
treeefb4daa1605df02b5a07df99cbcb0f82dbbda701
parente2287a42bce9080ed42b46cc9e8d544838236ec1 (diff)
downloadale-1167616726f9e995da9ac5b674cf6ded2d221855.zip
Add gometalinter for go files
Linter is disabled by default (see g:ale_go_gometalinter_enabled) as it conflicts with a number of established ALE linters (golint, govet, gosimple, staticcheck, etc).
-rw-r--r--ale_linters/go/gometalinter.vim61
1 files changed, 61 insertions, 0 deletions
diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim
new file mode 100644
index 00000000..3a827fd3
--- /dev/null
+++ b/ale_linters/go/gometalinter.vim
@@ -0,0 +1,61 @@
+" Author: Ben Reedy <https://github.com/breed808>
+" Description: Adds support for the gometalinter suite for Go files
+
+" Disable gometalinter by default
+if !exists('g:ale_go_gometalinter_enabled')
+ let g:ale_go_gometalinter_enabled = 0
+endif
+
+if !exists('g:ale_go_gometalinter_options')
+ let g:ale_go_gometalinter_options = ''
+endif
+
+function! ale_linters#go#gometalinter#GetCommand(buffer) abort
+ if g:ale_go_gometalinter_enabled == 1
+ return 'gometalinter ' . g:ale_go_gometalinter_options . ' ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+ endif
+ return ''
+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,
+\})