Skip to content

Commit 7a1483f

Browse files
authored
Add --warnings flag for buildifier (#197)
In your vimrc you can do e.g. call glaive#Install() Glaive codefmt buildifier_lint_mode='fix' Glaive codefmt buildifier_warnings='-module-docstring,+unsorted-dict-items' to get buildifier to ignore missing module docstrings but sort dictionaries automatically. The default behaviour is unchanged.
1 parent b5270ae commit 7a1483f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

autoload/codefmt/buildifier.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ function! codefmt#buildifier#GetFormatter() abort
4141
function l:formatter.Format() abort
4242
let l:lint_flag = s:plugin.Flag('buildifier_lint_mode')
4343
let l:cmd = [ s:plugin.Flag('buildifier_executable') ]
44-
if l:lint_flag != ""
44+
if !empty(l:lint_flag)
4545
let l:cmd += ["--lint=" . l:lint_flag]
4646
endif
47+
let l:warnings_flag = s:plugin.Flag('buildifier_warnings')
48+
if !empty(l:warnings_flag)
49+
let l:cmd += ["--warnings=" . l:warnings_flag]
50+
endif
4751
let l:fname = expand('%:p')
4852
if !empty(l:fname)
4953
let l:cmd += ['-path', l:fname]

doc/codefmt.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ Options:
117117
an error and do no formatting.
118118
Default: '' `
119119

120+
*codefmt:buildifier_warnings*
121+
The warnings passed to buildifier to modify the defaults. Whatever is
122+
specified is added to the commandline after '--warnings='. For example, if you
123+
add this to your config:
124+
125+
Glaive codefmt buildifier_warnings='-module-docstring,+unsorted-dict-items'
126+
127+
Then buildifier will omit the 'module-docstring' warning, but add
128+
'unsorted-dict-items' (which is ignored by default). This works also in
129+
fix-mode, in which case dictionary items will be resorted upon buffer save.
130+
131+
Options:
132+
"" (empty): Use default warnings from buildifier.
133+
"-some-warning": Remove 'some-warning' from the warning set.
134+
"+some-warning": Add 'some-warning' to the warning set.
135+
Default: ''
136+
120137
*codefmt:google_java_executable*
121138
The path to the google-java executable. Generally, this should have the form:
122139
`java -jar /path/to/google-java`

instant/flags.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ call s:plugin.Flag('buildifier_executable', 'buildifier')
111111
" cause an error and do no formatting.
112112
call s:plugin.Flag('buildifier_lint_mode', '')
113113

114+
""
115+
" The warnings for buildifier. passed to buildifier --warnings parameter.
116+
"
117+
" Options:
118+
"" (empty): Use default warnings from buildifier.
119+
"-some-warning": Remove 'some-warning' from the warning set.
120+
"+some-warning": Add 'some-warning' to the warning set.
121+
call s:plugin.Flag('buildifier_warnings', '')
122+
114123
""
115124
" The path to the google-java executable. Generally, this should have the
116125
" form:

0 commit comments

Comments
 (0)