buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

load-on-top should put the load at the right location

Open laurentlb opened this issue 2 years ago • 2 comments

When a load statement is put to the top with buildifier --lint=fix --warnings=load-on-top, the statement is added to the end of the loads. This means the statement is not placed correctly according to --warnings=out-of-order-load.

laurentlb avatar Sep 16 '21 14:09 laurentlb

Should load-on-top also sort the load statements that are already on top if they are not sorted? Should it do anything if all load statements are already on top but not sorted?

vladmos avatar Sep 19 '21 12:09 vladmos

A simple solution is to assume that the statements are sorted and try to find the correct place to insert. This guarantees we're not regressing.

I don't know if we should sort the existing statements. It increases the diff, but maybe it's okay.

My end goal is to have out-of-order-load on by default in the formatter, but this will require updating lots of existing files. I think it would improve the user experience (they don't have to think where to put a load), and it's done by formatters in other languages.

laurentlb avatar Sep 20 '21 11:09 laurentlb