blacken-docs
blacken-docs copied to clipboard
Support Ruff formatter as an alternative for Black
Description
Ruff formatter can replace Black, and it's much faster: https://docs.astral.sh/ruff/formatter/
I suggest supporting it as an option while keeping Black the default Python formatter. Opting for Ruff can be done via a flag or persistent file configuration.
Implementation-wise it would be different from Black, as Ruff does not have a Python API. It's achievable though.
What do you think?
Yeah, now Ruff has a formatter, I’d be tempted to add this and rename the project to format-docs or similar.
I think without a Ruff Python API, it wouldn't be particularly feasible. The only alternative would be to shell out to ruff format for each snippet, which would be slow due to process launch overhead (no matter how fast Ruff is).
I found the upstream Python API issue: https://github.com/astral-sh/ruff/issues/659
Seem this can now be done via https://github.com/amyreese/ruff-api
Thanks for the link, but I’d rather not depend on a “highly experimental” third-party package.
Ruff plans to implement this functionality: https://github.com/astral-sh/ruff/issues/8237