Skip to content

Commit f393d51

Browse files
authored
Add --lint_mode flag for buildifier (#192)
In your vimrc you can do e.g. call glaive#Install() Glaive codefmt buildifier_lint_mode='fix' to get buildifier to autofix issues. The default behaviour is unchanged.
1 parent 27e5ac2 commit f393d51

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

autoload/codefmt/buildifier.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ function! codefmt#buildifier#GetFormatter() abort
3939
" @flag(buildifier)
4040
" @throws ShellError
4141
function l:formatter.Format() abort
42+
let l:lint_flag = s:plugin.Flag('buildifier_lint_mode')
4243
let l:cmd = [ s:plugin.Flag('buildifier_executable') ]
44+
if l:lint_flag != ""
45+
let l:cmd += ["--lint=" . l:lint_flag]
46+
endif
4347
let l:fname = expand('%:p')
4448
if !empty(l:fname)
4549
let l:cmd += ['-path', l:fname]

doc/codefmt.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ Default: 'gn' `
105105
The path to the buildifier executable.
106106
Default: 'buildifier' `
107107

108+
*codefmt:buildifier_lint_mode*
109+
Buildifier --lint=lint_mode parameter. Set to 'fix' to autofix issues.
110+
Default: '' to not pass the flag and use the buildifier default (off)
111+
Off: Do not fix issues.
112+
Fix: Fix issues automatically during formatting.
113+
Warn: Format only if there are no issues; if there are issues
114+
it will cause an error and do no formatting.
115+
108116
*codefmt:google_java_executable*
109117
The path to the google-java executable. Generally, this should have the form:
110118
`java -jar /path/to/google-java`

instant/flags.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ call s:plugin.Flag('gn_executable', 'gn')
100100
" The path to the buildifier executable.
101101
call s:plugin.Flag('buildifier_executable', 'buildifier')
102102

103+
""
104+
" The lint_mode for buildifier, defaults to not passing the flag.
105+
" set to 'fix' to fix issues automatically during formatting,
106+
" or 'off' to explicitly not fix issues (the current buildifier default).
107+
" Setting to 'warn' will format only if there are no issues; if there are
108+
" issues it will cause an error and do no formatting.
109+
call s:plugin.Flag('buildifier_lint_mode', '')
110+
103111
""
104112
" The path to the google-java executable. Generally, this should have the
105113
" form:

0 commit comments

Comments
 (0)