2017-12-04 18:42:36 +00:00
|
|
|
" Author: Ben Reedy <https://github.com/breed808>, Jeff Willette <jrwillette88@gmail.com>
|
2017-04-13 09:25:35 +00:00
|
|
|
" Description: Adds support for the gometalinter suite for Go files
|
|
|
|
|
2017-07-06 23:10:30 +00:00
|
|
|
call ale#Set('go_gometalinter_options', '')
|
|
|
|
call ale#Set('go_gometalinter_executable', 'gometalinter')
|
2017-12-04 18:42:36 +00:00
|
|
|
call ale#Set('go_gometalinter_lint_package', 0)
|
2017-07-06 23:10:30 +00:00
|
|
|
|
2017-04-13 09:25:35 +00:00
|
|
|
function! ale_linters#go#gometalinter#GetCommand(buffer) abort
|
2017-12-04 18:42:36 +00:00
|
|
|
let l:filename = expand('#' . a:buffer . ':t')
|
2017-07-06 23:10:30 +00:00
|
|
|
let l:options = ale#Var(a:buffer, 'go_gometalinter_options')
|
2017-12-04 18:42:36 +00:00
|
|
|
let l:lint_package = ale#Var(a:buffer, 'go_gometalinter_lint_package')
|
|
|
|
|
|
|
|
" BufferCdString is used so that we can be sure the paths output from gometalinter can
|
|
|
|
" be calculated to absolute paths in the Handler
|
|
|
|
if l:lint_package
|
|
|
|
return ale#path#BufferCdString(a:buffer)
|
2018-08-02 22:44:12 +00:00
|
|
|
\ . '%e'
|
2017-12-04 18:42:36 +00:00
|
|
|
\ . (!empty(l:options) ? ' ' . l:options : '') . ' .'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ale#path#BufferCdString(a:buffer)
|
2018-08-02 22:44:12 +00:00
|
|
|
\ . '%e'
|
2017-12-04 18:42:36 +00:00
|
|
|
\ . ' --include=' . ale#Escape(ale#util#EscapePCRE(l:filename))
|
|
|
|
\ . (!empty(l:options) ? ' ' . l:options : '') . ' .'
|
2017-04-13 09:25:35 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-04-29 16:33:18 +00:00
|
|
|
function! ale_linters#go#gometalinter#GetMatches(lines) abort
|
|
|
|
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:?:?(warning|error):?\s\*?(.+)$'
|
|
|
|
|
|
|
|
return ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
endfunction
|
|
|
|
|
2017-04-13 09:25:35 +00:00
|
|
|
function! ale_linters#go#gometalinter#Handler(buffer, lines) abort
|
2017-12-04 18:42:36 +00:00
|
|
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
2017-04-13 09:25:35 +00:00
|
|
|
let l:output = []
|
|
|
|
|
2017-04-29 16:33:18 +00:00
|
|
|
for l:match in ale_linters#go#gometalinter#GetMatches(a:lines)
|
2017-12-04 18:42:36 +00:00
|
|
|
" l:match[1] will already be an absolute path, output from gometalinter
|
2017-04-13 09:25:35 +00:00
|
|
|
call add(l:output, {
|
2017-12-04 18:42:36 +00:00
|
|
|
\ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
|
2017-04-29 16:33:18 +00:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
2017-08-08 07:39:13 +00:00
|
|
|
\ 'type': tolower(l:match[4]) is# 'warning' ? 'W' : 'E',
|
2017-04-29 16:33:18 +00:00
|
|
|
\ 'text': l:match[5],
|
2017-04-13 09:25:35 +00:00
|
|
|
\})
|
|
|
|
endfor
|
2017-04-15 20:04:43 +00:00
|
|
|
|
2017-04-13 09:25:35 +00:00
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('go', {
|
|
|
|
\ 'name': 'gometalinter',
|
2018-08-02 22:44:12 +00:00
|
|
|
\ 'executable_callback': ale#VarFunc('go_gometalinter_executable'),
|
2017-04-13 09:25:35 +00:00
|
|
|
\ 'command_callback': 'ale_linters#go#gometalinter#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#go#gometalinter#Handler',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|