bazel-contrib / bazel-contrib/buildtools

Buildozer add command does not respect tables or add_tables

Open
#1,320 0 comments 0 reactions 0 assignees View on GitHub
P3
Dominant language
Go
Stars
1.2k
Forks
471
Avg merge
2d 22h
Merged PRs (30d)
13

Description

Running `buildozer add` with a list argument (ex: `buildozer add foo c b a`) will _always_ sort the list before adding, regardless of any tables or add_tables you may pass it.

I believe this is because the `AddValueToListAttribute` function sorts on everything other than `args`. https://github.com/bazelbuild/buildtools/blob/main/edit/edit.go#L826

Ideally buildozer would respect the same tables that buildifier would, or perhaps it would be better to defer all of the sorting to buildifier?

Buildozer test case:
```
function test_unsorted_other_attr() {
in='go_library(
name = "edit",
deps = [],
other_attr = []
)'
run "$in" 'add other_attr z y x' '//pkg:edit'
assert_equals 'go_library(
name = "edit",
deps = [
],
other_attr = [
"z",
"y",
"x",
]
)'
}
```

Contributor guide

Open the contributing guide

Research direction

Start by inspecting AddValueToListAttribute in edit/edit.go, especially how it handles args versus other attributes and the tables or add_tables options. Run the Buildozer test case shown in the issue and update the behavior so other_attr preserves the supplied order when sorting is not requested; the test should pass with z, y, x unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.