mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-07 10:21:05 +08:00
Switch to using buildifier's -path option (#3640)
Buildifier offers a -path command line option: > Buildifier's reformatting depends in part on the path to the file > relative to the workspace directory. Normally buildifier deduces > that path from the file names given, but the path can be given > explicitly with the -path argument. This is especially useful when > reformatting standard input, or in scripts that reformat a temporary > copy of a file. This lets us drop our `-type`-guessing logic. For the moment, we rely on the buffer filename being "relative to the workspace directory", which it generally is, but in a future change, we should introduce logic that will locate the WORKSPACE file and adjusts the filename relative to that directory. This could be complicated based on the working directory in which `buildifier` is executed, so a little more research is necessary to implement that logic correctly.
This commit is contained in:
@@ -14,20 +14,9 @@ endfunction
|
||||
function! ale#fixers#buildifier#Fix(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 = fnamemodify(bufname(a:buffer), ':t')
|
||||
let l:filename = ale#Escape(bufname(a:buffer))
|
||||
|
||||
let l:command = l:executable . ' -mode fix -lint fix'
|
||||
|
||||
" Attempt to guess the file type based on the filename. buildifier itself
|
||||
" usually does this based on the filenames provided on the command line,
|
||||
" but because we're piping our buffer via stdin, we do this manually.
|
||||
if l:filename =~? 'WORKSPACE'
|
||||
let l:command .= ' -type workspace'
|
||||
elseif l:filename =~? 'BUILD'
|
||||
let l:command .= ' -type build'
|
||||
elseif l:filename =~? '.bzl$'
|
||||
let l:command .= ' -type bzl'
|
||||
endif
|
||||
let l:command = l:executable . ' -mode fix -lint fix -path ' . l:filename
|
||||
|
||||
if l:options isnot# ''
|
||||
let l:command .= ' ' . l:options
|
||||
|
||||
Reference in New Issue
Block a user