buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

intended behavior of movePackageToTop

Open benjaminp opened this issue 5 years ago • 2 comments

The implementation of fix movePackageToTop has a comment that suggests it will make the package( call the first statement after any comments: https://github.com/bazelbuild/buildtools/blob/b1667ff58f714d13c2bba6823d6c52214705508f/edit/fix.go#L401-L403 However, the implementation will put the package declaration after loads, assignments, and docstrings in addition to comments. Which is the intended behavior?

(FWIW, the fact that movePackageToTop won't lift the package declaration above load statements makes the replace_load buildozer command less useful.)

benjaminp avatar Jul 21 '20 20:07 benjaminp

The comment is outdated, by convention docstrings and load statements should be on the top. Buildifier's linter warns if a file has a package() statement before a load().

Why does it make the replace_load command less useful?

vladmos avatar Jul 21 '20 22:07 vladmos

I see. For some reason I thought that package() should always be the first statement, so I was confused when replace_load followed by movePackageToTop didn't put the package above the new load.

benjaminp avatar Jul 21 '20 23:07 benjaminp