]> git.madduck.net Git - etc/vim.git/blob - ale_linters/bzl/buildifier.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 / bzl / buildifier.vim
1 " Author: Chuck Grindel <chuck.grindel@gmail.com>
2 " Description: Bazel Starlark lint support using buildifier.
3
4 function! ale_linters#bzl#buildifier#GetCommand(buffer) abort
5     let l:executable = ale#Escape(ale#fixers#buildifier#GetExecutable(a:buffer))
6     let l:options = ale#Var(a:buffer, 'bazel_buildifier_options')
7     let l:filename = ale#Escape(bufname(a:buffer))
8
9     let l:command = l:executable . ' -mode check -lint warn -path %s'
10
11     if l:options isnot# ''
12         let l:command .= ' ' . l:options
13     endif
14
15     return l:command
16 endfunction
17
18 function! ale_linters#bzl#buildifier#Handle(buffer, lines) abort
19     let l:pattern = '\v^[^:]+:(\d+):(\d+)?:?\s+(syntax error near)?(.+)$'
20     let l:output = []
21
22     for l:match in ale#util#GetMatches(a:lines, l:pattern)
23         call add(l:output, {
24         \   'lnum': l:match[1] + 0,
25         \   'col': l:match[2] + 0,
26         \   'text': l:match[3] . l:match[4],
27         \   'type': l:match[3] is# 'syntax error near' ? 'E' : 'W',
28         \})
29     endfor
30
31     return l:output
32 endfunction
33
34 call ale#linter#Define('bzl', {
35 \   'name': 'buildifier',
36 \   'output_stream': 'both',
37 \   'executable': function('ale#fixers#buildifier#GetExecutable'),
38 \   'command': function('ale_linters#bzl#buildifier#GetCommand'),
39 \   'callback': function('ale_linters#bzl#buildifier#Handle'),
40 \})