buildtools
buildtools copied to clipboard
Make new_load add loads in sorted order when possible
I understand that some files have out-of-order loads to begin with (or even loads scattered across the file). But when the existing loads are sorted, it could be nice to insert the new load in sorted order.
The workaround is to run out-of-order-load
manually.
Here's a simple usage that shows a load added out of order, followed by an out-of-order-load
run to fix it:
$ echo 'load("//a:foo.bzl", "foo")' > BUILD
$ buildozer 'new_load //z:bar.bzl bar' ./BUILD
fixed /tmp/tmp.qZXgFFm9vx/BUILD
$ cat ./BUILD
load("//z:bar.bzl", "bar")
load("//a:foo.bzl", "foo")
$ buildifier --lint=fix --warnings=out-of-order-load ./BUILD
$ cat ./BUILD
load("//a:foo.bzl", "foo")
load("//z:bar.bzl", "bar")
This would help immensely when doing merges, triggering less conflicts. Right now every new load triggers a conflict.