]> git.madduck.net Git - etc/vim.git/blob - ale_linters/go/gobuild.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / go / gobuild.vim
1 " Author: Joshua Rubin <joshua@rubixconsulting.com>, Ben Reedy <https://github.com/breed808>,
2 " Jeff Willette <jrwillette88@gmail.com>
3 " Description: go build for Go files
4 " inspired by work from dzhou121 <dzhou121@gmail.com>
5
6 call ale#Set('go_go_executable', 'go')
7 call ale#Set('go_gobuild_options', '')
8
9 function! ale_linters#go#gobuild#GetMatches(lines) abort
10     " Matches patterns like the following:
11     "
12     " file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args
13     " 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)
14     " file.go:5:2: expected declaration, found 'STRING' "log"
15     " go test returns relative paths so use tail of filename as part of pattern matcher
16     let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:? (.+)$'
17
18     return ale#util#GetMatches(a:lines, l:pattern)
19 endfunction
20
21 function! ale_linters#go#gobuild#Handler(buffer, lines) abort
22     let l:dir = expand('#' . a:buffer . ':p:h')
23     let l:output = []
24
25     for l:match in ale_linters#go#gobuild#GetMatches(a:lines)
26         call add(l:output, {
27         \   'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
28         \   'lnum': l:match[2] + 0,
29         \   'col': l:match[3] + 0,
30         \   'text': l:match[4],
31         \   'type': 'E',
32         \})
33     endfor
34
35     return l:output
36 endfunction
37
38 call ale#linter#Define('go', {
39 \   'name': 'gobuild',
40 \   'aliases': ['go build'],
41 \   'executable': {b -> ale#Var(b, 'go_go_executable')},
42 \   'cwd': '%s:h',
43 \   'command': {b ->
44 \       ale#go#EnvString(b)
45 \       . ale#Escape(ale#Var(b, 'go_go_executable')) . ' test'
46 \       . ale#Pad(ale#Var(b, 'go_gobuild_options'))
47 \       . ' -c -o /dev/null ./'
48 \   },
49 \   'output_stream': 'stderr',
50 \   'callback': 'ale_linters#go#gobuild#Handler',
51 \   'lint_file': 1,
52 \})