Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion autoload/codefmt/buildifier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ function! codefmt#buildifier#GetFormatter() abort
function l:formatter.Format() abort
let l:lint_flag = s:plugin.Flag('buildifier_lint_mode')
let l:cmd = [ s:plugin.Flag('buildifier_executable') ]
if l:lint_flag != ""
if !empty(l:lint_flag)
let l:cmd += ["--lint=" . l:lint_flag]
endif
let l:warnings_flag = s:plugin.Flag('buildifier_warnings')
if !empty(l:warnings_flag)
let l:cmd += ["--warnings=" . l:warnings_flag]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if there are spaces in the flag value this will do the right thing since maktaba#syscall will do escaping, but could you verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by 'the right thing', since spaces are not allowed in this flag. I could add a check and throw an error in that case, but then the question arises; why not check all other invalid characters as well?

I tried this:

Glaive codefmt buildifier_lint_mode='' buildifier_warnings='+unsorted-dict-items --lint=invalid'

and it just ignores the invalid flag - so I guess it must be inserting a backslash before the space and therefore not passing --line=invalid as a separate argument. If we later add a flag that is allowed to contain spaces, this should do the right thing.

endif
let l:fname = expand('%:p')
if !empty(l:fname)
let l:cmd += ['-path', l:fname]
Expand Down
17 changes: 17 additions & 0 deletions doc/codefmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ Options:
an error and do no formatting.
Default: '' `

*codefmt:buildifier_warnings*
The warnings passed to buildifier to modify the defaults. Whatever is
specified is added to the commandline after '--warnings='. For example, if you
add this to your config:

Glaive codefmt buildifier_warnings='-module-docstring,+unsorted-dict-items'

Then buildifier will omit the 'module-docstring' warning, but add
'unsorted-dict-items' (which is ignored by default). This works also in
fix-mode, in which case dictionary items will be resorted upon buffer save.

Options:
"" (empty): Use default warnings from buildifier.
"-some-warning": Remove 'some-warning' from the warning set.
"+some-warning": Add 'some-warning' to the warning set.
Default: ''

*codefmt:google_java_executable*
The path to the google-java executable. Generally, this should have the form:
`java -jar /path/to/google-java`
Expand Down
9 changes: 9 additions & 0 deletions instant/flags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ call s:plugin.Flag('buildifier_executable', 'buildifier')
" cause an error and do no formatting.
call s:plugin.Flag('buildifier_lint_mode', '')

""
" The warnings for buildifier. passed to buildifier --warnings parameter.
"
" Options:
"" (empty): Use default warnings from buildifier.
"-some-warning": Remove 'some-warning' from the warning set.
"+some-warning": Add 'some-warning' to the warning set.
call s:plugin.Flag('buildifier_warnings', '')

""
" The path to the google-java executable. Generally, this should have the
" form:
Expand Down