summaryrefslogtreecommitdiff
path: root/ale_linters/bzl
diff options
context:
space:
mode:
authorChuck Grindel <chuck.grindel@gmail.com>2023-06-27 03:52:25 -0600
committerGitHub <noreply@github.com>2023-06-27 18:52:25 +0900
commit21f1ab6ffc5ea958d558a5d9f5b0e5ab9110ee4e (patch)
tree083259445282135eda8e975557b30afc31bf8326 /ale_linters/bzl
parent5ab35a7a30e4ce000840f9caba3deabf86d2d030 (diff)
downloadale-21f1ab6ffc5ea958d558a5d9f5b0e5ab9110ee4e.zip
feat: support Bazel `buildifier` linter (#4529)
* Initial buildifier linter files * Add handler test * Fix test when options are not set
Diffstat (limited to 'ale_linters/bzl')
-rw-r--r--ale_linters/bzl/buildifier.vim40
1 files changed, 40 insertions, 0 deletions
diff --git a/ale_linters/bzl/buildifier.vim b/ale_linters/bzl/buildifier.vim
new file mode 100644
index 00000000..42cd3cd9
--- /dev/null
+++ b/ale_linters/bzl/buildifier.vim
@@ -0,0 +1,40 @@
+" Author: Chuck Grindel <chuck.grindel@gmail.com>
+" Description: Bazel Starlark lint support using buildifier.
+
+function! ale_linters#bzl#buildifier#GetCommand(buffer) abort
+ let l:executable = ale#Escape(ale#fixers#buildifier#GetExecutable(a:buffer))
+ let l:options = ale#Var(a:buffer, 'bazel_buildifier_options')
+ let l:filename = ale#Escape(bufname(a:buffer))
+
+ let l:command = l:executable . ' -mode check -lint warn -path %s'
+
+ if l:options isnot# ''
+ let l:command .= ' ' . l:options
+ endif
+
+ return l:command
+endfunction
+
+function! ale_linters#bzl#buildifier#Handle(buffer, lines) abort
+ let l:pattern = '\v^[^:]+:(\d+):(\d+)?:?\s+(syntax error near)?(.+)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[3] . l:match[4],
+ \ 'type': l:match[3] is# 'syntax error near' ? 'E' : 'W',
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('bzl', {
+\ 'name': 'buildifier',
+\ 'output_stream': 'both',
+\ 'executable': function('ale#fixers#buildifier#GetExecutable'),
+\ 'command': function('ale_linters#bzl#buildifier#GetCommand'),
+\ 'callback': function('ale_linters#bzl#buildifier#Handle'),
+\})