bazel-contrib / bazel-contrib/buildtools

buildozer: support regex in move

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

Description

Currently, the "move" command does not support specifying the value in terms of a regexp. I suppose this is because it prefers to support better matching for labels. Hot-changing it is really easy: I'm leaving the diff here if anybody needs it in the future, and searches the issues:

```diff
diff --git a/edit/edit.go b/edit/edit.go
index e56ee45..855d729 100644
--- a/edit/edit.go
+++ b/edit/edit.go
@@ -691,7 +691,8 @@ func RemoveFromList(li *build.ListExpr, item, pkg string, deleted **build.String
var all []build.Expr
for _, elem := range li.List {
if str, ok := elem.(*build.StringExpr); ok {
- if labels.Equal(str.Value, item, pkg) && (DeleteWithComments || !hasComments(str)) {
+ matched, err := regexp.Match(item, []byte(str.Value))
+ if matched && err == nil && (DeleteWithComments || !hasComments(str)) {
if deleted != nil {
*deleted = str
}
```

Apply and rebuild. `move` will take regexps instead of labels.

Contributor guide

Open the contributing guide

Research direction

Start in edit/edit.go at RemoveFromList, using the diff in the issue as the implementation reference. Rebuild buildozer and verify that the move command accepts a regular expression and matches the intended list values without breaking existing label behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, cli
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.