bazel-contrib / bazel-contrib/buildtools

[buildifier][Feature Request]: Add Warning for Recursive Glob for Source Files

Open
#1,292 1 comment 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

# Summary

buildifier should include a warning that checks for the use of recursive glob patterns (`glob(["**/*.java"])`) in Bazel build files, as recommended in the [Bazel build style guide](https://bazel.build/build/style-guide#recursive).

# Motivation

We have encountered a problem where some source files were not being found due to the use of a recursive glob pattern in our Bazel build files. The issue was particularly confusing for our developers, as the missing files were difficult to diagnose due to the nested build files and the combination of local and sandbox builds.

The Bazel build style guide recommends against using recursive glob patterns, as they can lead to unintended consequences and performance issues. Specifically, the guide states[^1]:
>* Recursive globs make BUILD files difficult to reason about because they skip subdirectories containing BUILD files.
>* Recursive globs are generally less efficient than having a BUILD file per directory with a dependency graph defined between them as this enables better remote caching and parallelism.
>* It is good practice to author a BUILD file in each directory and define a dependency graph between them.

# Proposed Change

buildifier should include a new warning `recursiveGlobPatternWarning` that checks for the use of recursive glob patterns in Bazel build files. The warning should suggest using explicit lists of files or non-recursive globs instead.

# Implementation Reference

The implementation for this warning would likely be similar to [constantGlobPatternWarning](https://github.com/bazelbuild/buildtools/blob/dd10159baa91487a419105ca0e0d1ab99eb3fec8/warn/warn_bazel.go#L36). However, as I am not an expert in the buildifier project or Go, I would love to find someone with more experience in this area to implement the proposed change. 🤞

[^1]: https://bazel.build/build/style-guide#recursive

Contributor guide

Open the contributing guide

Research direction

Start in warn/warn_bazel.go with constantGlobPatternWarning, the referenced analogous implementation. Done means recursive glob patterns such as glob(["**/*.java"]) produce recursiveGlobPatternWarning and suggest explicit file lists or non-recursive globs.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.