Skip to content

Commit 343cadb

Browse files
committed
Fix buildifier error reporting.
This was broken by 4b6cb67, which caused error messages to contain the filename rather than 'stdin'. Fixes google#103
1 parent 232226e commit 343cadb

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

autoload/codefmt/buildifier.vim

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ function! codefmt#buildifier#GetFormatter() abort
5454
" Parse all the errors and stick them in the quickfix list.
5555
let l:errors = []
5656
for line in split(v:exception, "\n")
57-
let l:tokens = matchlist(line, '\C\v^stdin:(\d+):(\d+):\s*(.*)')
57+
if empty(l:fname)
58+
let l:fname_pattern = 'stdin'
59+
else
60+
let l:fname_pattern = escape(l:fname, '\')
61+
endif
62+
let l:tokens = matchlist(line,
63+
\ '\C\v^\V'. l:fname_pattern . '\v:(\d+):(\d+):\s*(.*)')
5864
if !empty(l:tokens)
5965
call add(l:errors, {
6066
\ "filename": @%,

vroom/buildifier.vroom

+42
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,45 @@ Errors are reported using the quickfix list.
7575
:echomsg string(map(getqflist(),
7676
|'v:val.lnum . "," . v:val.col . "," . v:val.text'))
7777
~ ['2,15,syntax error near ]']
78+
79+
Note that if the file's path was passed to buildifier, error reports are in a
80+
slightly different format, prefixed with the filename we passed.
81+
82+
@clear
83+
:silent file /foo/bar/BUILD
84+
:set filetype=bzl
85+
% load()
86+
87+
> go
88+
:FormatCode
89+
! buildifier .*2> (.*)
90+
$ echo '/foo/bar/BUILD:1:7: syntax error near )' >\1 (command)
91+
$ 1 (status)
92+
load()
93+
@end
94+
95+
We'll be on column 6 because there's no column 7. (Buildifier appears to always
96+
report one column past the actual error.)
97+
98+
:echomsg line('.') . ',' . col('.')
99+
~ 1,6
100+
:echomsg string(map(getqflist(),
101+
|'v:val.lnum . "," . v:val.col . "," . v:val.text'))
102+
~ ['1,7,syntax error near )']
103+
104+
If there are no errors, then the quickfix list is (currently, see
105+
https://github.com/google/vim-codefmt/issues/58) left alone:
106+
107+
> godd
108+
% load('@io_bazel_rules_go//proto:def.bzl','go_proto_library')
109+
> go
110+
111+
:FormatCode
112+
! buildifier -path /foo/bar/BUILD .*
113+
$ load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
114+
115+
:echomsg line('.') . ',' . col('.')
116+
~ 1,1
117+
:echomsg len(getqflist())
118+
~ 1
119+
:set filetype=

0 commit comments

Comments
 (0)