[buildifier] Preserve symbol semantics when removing unused loads. (#433)

When the same symbol is loaded multiple times, during evalution the
last symbol wins and all previous loads are ignored, but `buildifier`
would preserve the first instance and remove all other usages
which breaks semantics unless all loads are from the same file.

In other words

```
load(":defs1.bzl", "s1")
load(":defs2.bzl", "s1")
```

is equivalent to

```
load(":defs2.bzl", "s1")
```

but `buildifier` would produce

```
load(":defs1.bzl", "s1")
```

To address this, all statements are analyzed in a reverse order, so the very
last (in terms of line numbers) is preserved and all preceding loads are
removed. This also slightly simplifies `load` removal logic, since we no longer
need to adjust index.
2 files changed
tree: c1b8d48343d7b64aba6751f2019825acb5b1df51
  1. .bazelci/
  2. api_proto/
  3. build/
  4. build_proto/
  5. buildifier/
  6. buildifier2/
  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. lang/
  18. tables/
  19. testutils/
  20. unused_deps/
  21. warn/
  22. wspace/
  23. .gitignore
  24. BUILD.bazel
  25. CONTRIBUTING.md
  26. CONTRIBUTORS
  27. LICENSE
  28. README.md
  29. status.sh
  30. update_generated.sh
  31. WARNINGS.md
  32. WORKSPACE
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.