support AssignExpr statements in edit.FindRuleByName() (#1369)

* support AssignExpr statements in edit.FindRuleByName()

We have what is probably an unconventional style in some of our BUILD
files where a macro is used to define several targets and returns a
struct of some information so that things like labels of generated
targets can be passed as attributes to other targets in the same
BUILD file, without the BUILD file needing to hardcode or be aware of
the naming convention of the macro's internals.

buildozer and unused_deps are unable to operate on targets in
`AssignExpr` statements since `edit.FindRuleByName()` and
`edit.IndexOfRuleByName()` skip over any nodes that are not call
expressions. This commit adapts these functions to be able to find call
expressions that are on the right-hand side of an assignment expression.

fixes #1306

* refactor test based on feedback

* refactor check for CallExpr or AssignExpr based on feedback
2 files changed
tree: fa8d434a3d7151c88477e61aa060712b6be0d773
  1. .bazelci/
  2. .github/
  3. api_proto/
  4. build/
  5. build_proto/
  6. buildifier/
  7. buildozer/
  8. bzlenv/
  9. config/
  10. convertast/
  11. deps_proto/
  12. differ/
  13. edit/
  14. extra_actions_base_proto/
  15. file/
  16. generatetables/
  17. labels/
  18. lang/
  19. release/
  20. tables/
  21. testutils/
  22. unused_deps/
  23. warn/
  24. wspace/
  25. .bazelrc
  26. .bazelversion
  27. .gitignore
  28. .mailmap
  29. .pre-commit-config.yaml
  30. BUILD.bazel
  31. CODEOWNERS
  32. CONTRIBUTING.md
  33. CONTRIBUTORS
  34. go.mod
  35. go.sum
  36. launcher.js
  37. LICENSE
  38. MODULE.bazel
  39. README.md
  40. status.py
  41. update_generated.sh
  42. WARNINGS.md
  43. WORKSPACE
  44. WORKSPACE.bzlmod
README.md

Buildtools for bazel

This repository contains developer tools for working with Google's bazel buildtool.

Build status

Setup

See instructions in each tool's directory.