mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-03 01:53:30 +08:00
Add a buildifier fixer for Bazel files (#3499)
This fixer enables buildifier's formatting and "lint fix" modes. Additional options can be provided via `bazel_buildifier_options`. It also implements some basic logic for guessing the file's type. buildifier itself usually does this based on the filenames provided on the command line, but because we're piping our buffer via stdin, we need to do this manually.
This commit is contained in:
0
test/command_callback/bazel_paths/BUILD
Normal file
0
test/command_callback/bazel_paths/BUILD
Normal file
0
test/command_callback/bazel_paths/WORKSPACE
Normal file
0
test/command_callback/bazel_paths/WORKSPACE
Normal file
0
test/command_callback/bazel_paths/defs.bzl
Normal file
0
test/command_callback/bazel_paths/defs.bzl
Normal file
43
test/fixers/test_buildifier_fixer_callback.vader
Normal file
43
test/fixers/test_buildifier_fixer_callback.vader
Normal file
@@ -0,0 +1,43 @@
|
||||
Before:
|
||||
let g:ale_bazel_buildifier_options = ''
|
||||
call ale#assert#SetUpFixerTest('bzl', 'buildifier')
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownFixerTest()
|
||||
|
||||
Execute(The buildifier callback should return the correct default values):
|
||||
call ale#test#SetFilename('bazel_paths/WORKSPACE')
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape(g:ale_bazel_buildifier_executable)
|
||||
\ . ' -mode fix -lint fix -type workspace -'
|
||||
\ }
|
||||
|
||||
Execute(The buildifier callback should include any additional options):
|
||||
call ale#test#SetFilename('bazel_paths/WORKSPACE')
|
||||
let g:ale_bazel_buildifier_options = '--some-option'
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape(g:ale_bazel_buildifier_executable)
|
||||
\ . ' -mode fix -lint fix -type workspace --some-option -',
|
||||
\ }
|
||||
|
||||
Execute(The buildifier callback should recognize BUILD files):
|
||||
call ale#test#SetFilename('bazel_paths/BUILD')
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape(g:ale_bazel_buildifier_executable)
|
||||
\ . ' -mode fix -lint fix -type build -'
|
||||
\ }
|
||||
|
||||
Execute(The buildifier callback should recognize .bzl files):
|
||||
call ale#test#SetFilename('bazel_paths/defs.bzl')
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape(g:ale_bazel_buildifier_executable)
|
||||
\ . ' -mode fix -lint fix -type bzl -'
|
||||
\ }
|
||||
Reference in New Issue
Block a user