contrib(fmt): my yearning for a maudfmt
Hi there 🐱
I really love the way maud is making html templating in rust so easy and practical. It reminds me a lot of why I liked elm's syntax so much, and its pretty much an emmet on steroid - without the useless expanding.
Though as much as like writing maud macros, the formatting is such a pain having to manage it manually. I see that I am not the only one in the issues, with eboody even implementing an elegant nvim plugin in #473 for this purpose.
When I take a look around, I see that some neighbors like leptos implemented their own leptosfmt that runs alongside rustfmt to specifically format their macro blocks.
I'd love to have something similar as a binary formatter that is reliable and could be used in any editor or in pre-commit/CI.
I was sold: I'm gonna build maudfmt.
I started implementing the thing, parsing maud::html with syn and reproducing maud's ast, but I got a bit uneasy:
- the ast parser is already implemented in the
maud_macroscrate, and though available on crates.io the ast parser is private and unusable. - on top of having to re-implement the entire maud ast parser, I'd have to keep it in sync with maud's implementation (though I agree it shouldn't move much)
My questions are:
- would it be possible to somehow make maud's ast parser publicly available so I could use it in a
maudfmtcrate ? - else, would it be reasonable to ask if
maudfmtcould be developed in the upstream maud repo so we could share the ast parser in a mutual dependency crate ?
Other options I consider, though way dirtier:
- using a github submodules (better for staying synced with upstream, but doesn't fix the parser being private issue)
- copy the code I need like a little thief and use it in my crate (staying sync will suck)
Stating the obvious, I am more than willing to create/contribute/maintain maudfmt whatever the solution agreed upon is.
Thus I'd like your insights on the matter.
Thank you for taking the time to read my little story. Have a nice rest of your day/morning/night. 👋
Dioxus has a formatter for their macros. Maybe that can provide some ideas for your implementation. I would love to see a maud formatter.
Hi all !
Small update, the work is coming along nicely.
The formatting is still a bit quirky in some places and I'd like to make it "line-length and comment aware" before calling it really ready, but it is already more than usable as it formats indentation nicely and outputs valid maud.
Feel free to give it a try: https://github.com/Jeosas/maudfmt
I'm currently working on creating release workflow and hope to create a release with compiled binaries today.
You rock @Jeosas !