Skip to content

Commit f8c8945

Browse files
committed
Specify file type for buildifier explicitly
When formatting Bazel files, buildifier needs to know the concrete file type which it usually deduces from the file name which is impossible when operating on stdin. For example, the order of load statements in a WORKSPACE file is significant and re-ordering might break it.
1 parent d8ccc0b commit f8c8945

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog].
55

6+
## 4.5 (unreleased)
7+
### Formatters
8+
* Format Bazel files according to their type
9+
610
## 4.4 (released 2025-02-12)
711
### Bugs fixed
812
* `$PATH` was not correctly respected for some remote executables ([#341]).

apheleia-formatters.el

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@
3434
(apheleia-formatters-fill-column "--line-length")
3535
"-"))
3636
(brittany . ("brittany"))
37-
(buildifier . ("buildifier"))
37+
(buildifier . ("buildifier" "-type"
38+
(cond
39+
((eq major-mode 'bazel-workspace-mode) "workspace")
40+
((eq major-mode 'bazel-module-mode) "module")
41+
((eq major-mode 'bazel-build-mode) "build")
42+
(t "auto")
43+
)))
3844
(biome . ("apheleia-npx" "biome" "format" "--stdin-file-path" filepath))
3945
(caddyfmt . ("caddy" "fmt" "-"))
4046
(clang-format . ("clang-format"

0 commit comments

Comments
 (0)