tweag / topiary

https://topiary.tweag.io/
MIT License
533 stars 21 forks source link

Starlark Formatting #581

Open Xophmeister opened 1 year ago

Xophmeister commented 1 year ago

Is your feature request related to a problem? Please describe. We're often on the look-out for new languages to add support for, in Topiary. Starlark may be worth looking into, given our connection with the Scalable Builds Group.

Describe the solution you'd like Starlark formatting support in Topiary.

Describe alternatives you've considered I didn't immediately find any extant Starlark formatters (to be fair, I didn't look very hard). As Starlark is (IIRC) a subset of Python, it may be possible to format it with Python formatters, such as Black; I don't know if this is the usual approach. (@aherrmann Do you know the formatting story for Starlark?)

(If, e.g., Black is a viable formatter for Starlark, then that would deprioritise this issue.)

Additional context There are at least two Tree Sitter grammars for Starlark:

If we're going to support Python in the future, then supporting Starlark may be a good intermediary step.

(It's a big "if", which also applies to Starlark: It's not 100% clear that Topiary will work well with semantic-whitespace languages.)

ErinvanderVeen commented 1 year ago

I think the industry standard is Buildifier

aherrmann commented 1 year ago

As @ErinvanderVeen points out Buildifier is the standard formatter used for Bazel Starlark files. Next to formatting it also provides linting. For those who like pre-commit checks, there is also an integration. There is also Meta's Starlark-Rust which includes linting capabilities and a language server and VSCode extension.