]> git.madduck.net Git - etc/vim.git/blob - ale_linters/go/golangci_lint.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 / golangci_lint.vim
1 " Author: Sascha Grunert <mail@saschagrunert.de>
2 " Description: Adds support of golangci-lint
3
4 call ale#Set('go_golangci_lint_options', '')
5 call ale#Set('go_golangci_lint_executable', 'golangci-lint')
6 call ale#Set('go_golangci_lint_package', 1)
7
8 function! ale_linters#go#golangci_lint#GetExecutable(buffer) abort
9     let l:executable = ale#Var(a:buffer, 'go_golangci_lint_executable')
10
11     return l:executable
12 endfunction
13
14 function! ale_linters#go#golangci_lint#GetCommand(buffer, version) abort
15     let l:filename = expand('#' . a:buffer . ':t')
16     let l:options = ale#Var(a:buffer, 'go_golangci_lint_options')
17     let l:lint_package = ale#Var(a:buffer, 'go_golangci_lint_package')
18
19     if ale#semver#GTE(a:version, [2, 0, 0])
20         let l:options = l:options
21         \ . ' --output.json.path stdout'
22         \ . ' --output.text.path stderr'
23         \ . ' --show-stats=0'
24     else
25         let l:options = l:options
26         \   . ' --out-format=json'
27         \   . ' --show-stats=0'
28     endif
29
30     if l:lint_package
31         return ale#go#EnvString(a:buffer)
32         \   . '%e run '
33         \   .  l:options
34     endif
35
36     return ale#go#EnvString(a:buffer)
37     \   . '%e run '
38     \   . ale#Escape(l:filename)
39     \   . ' ' . l:options
40 endfunction
41
42 function! ale_linters#go#golangci_lint#Handler(buffer, lines) abort
43     let l:dir = expand('#' . a:buffer . ':p:h')
44     let l:output = []
45
46     let l:matches = ale#util#FuzzyJSONDecode(a:lines, [])
47
48     if empty(l:matches)
49         return []
50     endif
51
52     for l:match in l:matches['Issues']
53         if l:match['FromLinter'] is# 'typecheck'
54             let l:msg_type = 'E'
55         else
56             let l:msg_type = 'W'
57         endif
58
59         call add(l:output, {
60         \   'filename': ale#path#GetAbsPath(l:dir, fnamemodify(l:match['Pos']['Filename'], ':t')),
61         \   'lnum': l:match['Pos']['Line'] + 0,
62         \   'col': l:match['Pos']['Column'] + 0,
63         \   'type': l:msg_type,
64         \   'text': match['FromLinter'] . ' - ' . l:match['Text'],
65         \})
66     endfor
67
68     return l:output
69 endfunction
70
71 call ale#linter#Define('go', {
72 \   'name': 'golangci-lint',
73 \   'executable': function('ale_linters#go#golangci_lint#GetExecutable'),
74 \   'cwd': '%s:h',
75 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
76 \       buffer,
77 \       ale_linters#go#golangci_lint#GetExecutable(buffer),
78 \       '%e --version',
79 \       function('ale_linters#go#golangci_lint#GetCommand'),
80 \   )},
81 \   'callback': 'ale_linters#go#golangci_lint#Handler',
82 \   'lint_file': 1,
83 \})