Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PieterBunnenberg opened this issue Sep 9, 2024 · 0 comments

Comments

@PieterBunnenberg
Copy link

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.

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 states1:

  • 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. 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. 🤞

Footnotes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant