Skip to content

Commit 3e64439

Browse files
author
Chip Hogg
committed
Use --type instead of --path
`--path` is not working on buildifier 0.25.1. Fixes google#128, but only for users whose buildifier is newer than bazelbuild/buildtools#232. For other users, this will likely crash.
1 parent 18f47c3 commit 3e64439

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

autoload/codefmt/buildifier.vim

+27-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ function! codefmt#buildifier#GetFormatter() abort
3939
" @flag(buildifier)
4040
" @throws ShellError
4141
function l:formatter.Format() abort
42-
let l:cmd = [ s:plugin.Flag('buildifier_executable') ]
43-
let l:fname = expand('%:p')
44-
if !empty(l:fname)
45-
let l:cmd += ['-path', l:fname]
46-
endif
42+
let l:cmd = [
43+
\ s:plugin.Flag('buildifier_executable'),
44+
\ '--type='.s:BuildifierFileType()]
4745

4846
let l:input = join(getline(1, line('$')), "\n")
4947
try
@@ -54,6 +52,7 @@ function! codefmt#buildifier#GetFormatter() abort
5452
" Parse all the errors and stick them in the quickfix list.
5553
let l:errors = []
5654
for line in split(v:exception, "\n")
55+
let l:fname = expand('%:p')
5756
if empty(l:fname)
5857
let l:fname_pattern = 'stdin'
5958
else
@@ -82,3 +81,26 @@ function! codefmt#buildifier#GetFormatter() abort
8281

8382
return l:formatter
8483
endfunction
84+
85+
86+
""
87+
" @private
88+
"
89+
" The type of skylark file to format.
90+
function! s:BuildifierFileType() abort
91+
let l:fname = maktaba#path#Basename(expand('%:p'))
92+
93+
if maktaba#string#StartsWith(l:fname, 'BUILD')
94+
return 'build'
95+
endif
96+
97+
if maktaba#string#StartsWith(l:fname, 'WORKSPACE')
98+
return 'workspace'
99+
endif
100+
101+
if maktaba#string#EndsWith(l:fname, '.bzl')
102+
return 'bzl'
103+
endif
104+
105+
return 'auto'
106+
endfunction

0 commit comments

Comments
 (0)