From 6ad9e9442365845b1cc5a10035466cfcb1022675 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 4 Mar 2025 21:44:34 +0100 Subject: Specify file type for buildifier explicitly (#352) 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. --------- Co-authored-by: Radon Rosborough --- CHANGELOG.md | 4 ++++ apheleia-formatters.el | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880b04e..0adcab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog]. +## Unreleased +### Formatters +* Format Bazel files according to their type + ## 4.4 (released 2025-02-12) ### Bugs fixed * `$PATH` was not correctly respected for some remote executables ([#341]). diff --git a/apheleia-formatters.el b/apheleia-formatters.el index c12c970..e6adfaa 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -34,7 +34,13 @@ (apheleia-formatters-fill-column "--line-length") "-")) (brittany . ("brittany")) - (buildifier . ("buildifier")) + (buildifier . ("buildifier" "-type" + (cond + ((eq major-mode 'bazel-workspace-mode) "workspace") + ((eq major-mode 'bazel-module-mode) "module") + ((eq major-mode 'bazel-build-mode) "build") + (t "auto") + ))) (biome . ("apheleia-npx" "biome" "format" "--stdin-file-path" filepath)) (caddyfmt . ("caddy" "fmt" "-")) (clang-format . ("clang-format" -- cgit v1.0