ruff icon indicating copy to clipboard operation
ruff copied to clipboard

option to format other filetypes (eg. `toml`, `yaml`, `json`, `md`, etc.)

Open DetachHead opened this issue 1 year ago • 4 comments
trafficstars

it would be nice if ruff could format toml, yaml and md files.

i get that this may be considered out of scope for ruff, however in the nodejs ecosystem, the prettier formatter works on these filetypes in addition to js & ts files, which is useful because most projects contain files written in those languages.

DetachHead avatar Apr 02 '24 13:04 DetachHead

Wrap dprint 🚀🚀🚀

KotlinIsland avatar Apr 02 '24 13:04 KotlinIsland

This is related to https://github.com/astral-sh/ruff/issues/9244

Yeah, that's something I want to do eventually and we have the infrastructure for it (ruff_formatter is entirely language agnostic). But there are some things we have to figure out (what parsers to use or implement our own? How to integrate it into existing commands) and implementing additional language is a large commitment

MichaReiser avatar Apr 02 '24 13:04 MichaReiser

I'm serious about dprint, I would imagine it would be a massive amount of work, when dprint is doing exactly what you are setting out to achieve.

KotlinIsland avatar Apr 02 '24 22:04 KotlinIsland

Integrating dprint as an optional formatter (that we call into when the project has installed it) is an option. But I'm unsure if that's the experience users seek. We need to do some designing around this and decide if we want to build out support for new languages ourselves or delegate to other formatters (even Prettier)

MichaReiser avatar Apr 03 '24 06:04 MichaReiser

Ruffs formatter is already integrated into dprint https://github.com/dprint/dprint-plugin-ruff 🚀

KotlinIsland avatar May 29 '24 00:05 KotlinIsland

dprint also doesn't have a yaml formatter

DetachHead avatar May 29 '24 01:05 DetachHead

dprint also doesn't have a yaml formatter

I mean technically it has prettier as a process plugin. Which you can configure to run only on yaml. As much as I dislike prettier for JS/TS, it does just fine for markup/static languages.

There's also pre-commit's https://github.com/macisamuele/language-formatters-pre-commit-hooks which satisfies all my toml, yaml, ini, json (haven't tried the others) needs.

dprint also still doesn't work through pre-commit's free version if you have an online shared config.

Not saying this to discourage the OP's request. I too would like if Ruff handled common python config format (.ini for historical reasons for a bunch of tools, and toml). Just offering some options in the short term.

Avasam avatar May 29 '24 01:05 Avasam