bazel-contrib / bazel-contrib/buildtools

buildifier: Catch broad glob patterns and recursive globs

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

Description

Would it be possible for buildifier to detect and warn about the use of open ended glob patterns?

```starlark
filegroup(
name = "sources",
srcs = glob(["src/*"]),
)
```

I'm finding this pattern in quite a few places and it ends up introducing cache invalidation as local developers unknowingly have temp files rendered there by their IDE or some other process in their workflow, thus causing Bazel to rebuild targets when it shouldn't.

Instead, I'd want developers to add patterns similar to the following:
```diff
diff --git a/BUILD b/BUILD
index d88dd2b..77b4d51 100644
--- a/BUILD
+++ b/BUILD
@@ -1,4 +1,8 @@
filegroup(
name = "sources",
- srcs = glob(["src/*"]),
+ srcs = glob([
+ "src/*.rs",
+ "src/*.cc",
+ "src/*.h",
+ ]),
)
```

Contributor guide

Open the contributing guide

Research direction

Start by locating buildifier's handling of Starlark glob() calls and its warning checks for BUILD files. Reproduce the src/* example, then verify how broad and recursive patterns should warn while explicit extensions such as src/*.rs do not.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.