bazelbuild / buildtools

A bazel BUILD file formatter and editor
Apache License 2.0
1.03k stars 417 forks source link

use .buildifier-tables.json file without specifying on CLI #1181

Open peakschris opened 1 year ago

peakschris commented 1 year ago

We need to use a custom tables.json file with --add_tables or --tables. But it would help if we did not need to specify it on the command line each time. Some integrations such as VSCode auto-download buildifier and auto-run it.

Fixes could include:

Maybe I have missed something and this is already there -- if so it would be helpful to know. Thanks for a great tool!

CauhxMilloy commented 4 months ago

Just to reply and share, this is already possible. The Config struct defines all the fields for .buildifier.json. There is a AddTablesPath field, with json annotation for the name addTables. This means that "addTables": ".buildifier-tables.json" could be added to your .buildifier.json and it'll update necessary fields. Here's the struct that defines all the settings for what can go into .buildifier-tables.json.

I know this issue is a bit old, but I hope this reply helped (either for you or for people who find this in the future).

P.S. Note that there is also a TablesPath (as just tables in json), but I never use it (replacing is kinda annoying, IMO).

novas0x2a commented 2 months ago

One thing to note, though, is that the addTables path is always interpreted as relative to the buildifier CWD, meaning, if your CWD isn't at the root of the repo, something like this breaks buildifier:

{
    "AddTables": ".buildifier-tables.json"
}
denglesberg-splunk commented 1 month ago

Is there any known workaround to the issue with interpreting the addTables path relative to PWD rather than relative to the .buildifier.json file?