buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Make new_load add loads in sorted order when possible

Open cpovirk opened this issue 4 years ago • 1 comments

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")

cpovirk avatar Aug 12 '20 17:08 cpovirk

This would help immensely when doing merges, triggering less conflicts. Right now every new load triggers a conflict.

comius avatar Aug 13 '20 08:08 comius