buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

Formatting BUCK files

Open benbrittain opened this issue 2 years ago • 4 comments

I'm currently using buildifier to do formatting for our project. That being said, if we do wind up actually migrating from bazel to buck2, it would be nice if we could unify our tooling entirely. Are there any plans to leverage the starlark parser within buck2 to provide a formatting option (something like buck2 fmt)?

If there isn't a plan to bundle a formatter, would a contribution like this be well received?

benbrittain avatar Apr 25 '23 16:04 benbrittain

Buildifier works pretty well on BUCK files. find . -name BUCK | xargs -n1 buildifier -path=BUILD

dtolnay avatar Apr 25 '23 16:04 dtolnay

We're using buildifier for formatting the BUCK files already, it works fine. That being said, having an obvious single point of entry is always a nice. Not a big deal, but potentially nice quality of life improvement.

benbrittain avatar Apr 25 '23 17:04 benbrittain

The plan would be to add a formatter to the https://github.com/facebookexperimental/starlark-rust library, and then expose it through buck2 starlark fmt or similar. Vaguely something we'd like to do, but someone writing a formatter is the first step.

ndmitchell avatar Apr 26 '23 22:04 ndmitchell

NB: buildifier hard errors when the literal ... is used, e.g. in tuple[str, ...]:

$ echo "MyType = tuple[str, ...]" | buildifier
<stdin>:1:23: syntax error near .
<stdin> # reformat

Upstream:

  • https://github.com/bazelbuild/buildtools/issues/1405

9999years avatar Oct 17 '25 18:10 9999years