From 1167616726f9e995da9ac5b674cf6ded2d221855 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Thu, 13 Apr 2017 19:25:35 +1000 Subject: 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). --- ale_linters/go/gometalinter.vim | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ale_linters/go/gometalinter.vim (limited to 'ale_linters') 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 +" 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, +\}) -- cgit v1.2.3