Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 232226e

Browse files
Merge pull request #101 from malcolmr/buildifier-path
If the buffer has a path, pass it to buildifier as `-path PATH`.
2 parents 78f6465 + 4b6cb67 commit 232226e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

‎autoload/codefmt/buildifier.vim‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ function! codefmt#buildifier#GetFormatter() abort
3939
" @flag(buildifier)
4040
" @throws ShellError
4141
function l:formatter.Format() abort
42-
let l:cmd = s:plugin.Flag('buildifier_executable')
42+
let l:cmd = [ s:plugin.Flag('buildifier_executable') ]
43+
let l:fname = expand('%:p')
44+
if !empty(l:fname)
45+
let l:cmd += ['-path', l:fname]
46+
endif
47+
4348
let l:input = join(getline(1, line('$')), "\n")
4449
try
4550
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call()

‎vroom/buildifier.vroom‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
The built-in buildifier formatter knows how to format Bazel BUILD files. If you
2-
aren't familiar with basic codefmt usage yet, see main.vroom first.
1+
The built-in buildifier formatter knows how to format Bazel BUILD and .bzl
2+
files. If you aren't familiar with basic codefmt usage yet, see main.vroom
3+
first.
34

45
We'll set up codefmt and configure the vroom environment, then jump into some
56
examples.
@@ -38,14 +39,17 @@ buildifier_executable flag if the default of "buildifier" doesn't work.
3839
$ )
3940
:Glaive codefmt buildifier_executable='buildifier'
4041

41-
The bzl filetype will use the buildifier formatter by default.
42+
The bzl filetype will use the buildifier formatter by default. The path to the
43+
file being edited is passed to buildifier so that it can adjust to whether the
44+
file is a BUILD or .bzl file.
4245

4346
@clear
4447
% foo_library(name = "foo", srcs = ["bar.js"],)
4548

49+
:silent file /foo/bar/BUILD
4650
:set filetype=bzl
4751
:FormatCode
48-
! buildifier .*
52+
! buildifier -path /foo/bar/BUILD .*
4953
$ foo_library(
5054
$ name = "foo",
5155
$ srcs = ["bar.js"],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /