From b163fcf72b7def638f364ed129c9b28032c1d39b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 25 Aug 2023 14:09:32 +0200 Subject: [PATCH] Add `format` command to force unconditional formatting (#1186) This allows users of buildozer to format files without also having buildifier installed. This was possible previously by making a trivial edit and reverting it, but a dedicated command is cleaner. Will be used as part of the upcoming `bazel mod tidy` command. --- buildozer/README.md | 2 ++ buildozer/buildozer_test.sh | 18 ++++++++++++++++++ edit/buildozer.go | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/buildozer/README.md b/buildozer/README.md index 5d841c6a3..a8bbc7208 100644 --- a/buildozer/README.md +++ b/buildozer/README.md @@ -131,6 +131,8 @@ Buildozer supports the following commands(`'command args'`): * `dict_remove `: Deletes the key for the dict attribute `attr`. * `dict_list_add `: Adds value(s) to the list in the dict attribute `attr`. + * `format`: Force formatting of all files, even if they were not changed by + other commands. Here, `` represents an attribute (being `add`ed/`rename`d/`delete`d etc.), e.g.: `srcs`, `` represents values of the attribute and so on. diff --git a/buildozer/buildozer_test.sh b/buildozer/buildozer_test.sh index 43337e25c..bddaded14 100755 --- a/buildozer/buildozer_test.sh +++ b/buildozer/buildozer_test.sh @@ -2299,4 +2299,22 @@ EOF diff -u MODULE.bazel.expected MODULE.bazel || fail "Output didn't match" } +function test_format() { + cat > MODULE.bazel < MODULE.bazel.expected < "}, "use_repo_add": {cmdUseRepoAdd, false, 2, -1, "([dev] |) "}, "use_repo_remove": {cmdUseRepoRemove, false, 2, -1, "([dev] |) "}, + "format": {cmdFormat, false, 0, 0, ""}, } var readonlyCommands = map[string]bool{