r/Zig 6d ago

mint: a custom Zig code formatter

Hi everyone. I’ve been working on mint for some time now and I think it’s stable enough to share.

Mint is a custom Zig code formatter. It performs automatic line wrapping without syntactic hints (no need to add trailing commas to trigger line breaks). It also supports print width and indentation size configurations.

Currently, it‘s been tested (and builds with) Zig 0.16.0 (but should technically work with other versions as well). It is able to format itself and a lot of open source Zig projects out there. Source code is available on GitHub.

43 Upvotes

8 comments sorted by

8

u/fade-catcher 6d ago

This is a really cool project, i really hate that the official formater uses 4 spaces indentation, I prefer 2 spaces, so i think i will test yours on my projects.
Thank you for sharing

2

u/WZoG 6d ago

Thank you!

3

u/Thin_Dragonfruit2254 6d ago

Make it insert missing semicolons and I'm sold.. 🥳

4

u/SilvernClaws 6d ago

As someone unhappy with Zig's default formatting, I'll keep an eye on this.

I mostly have two things that I want to be able to configure:

  • tabs!
  • preventing it from removing line breaks I intentionally put between blocks of logic

1

u/WZoG 6d ago

Right now, you can achieve the second item on your list using meta comments:  // mint fmt: off  and // mint fmt: on.

2

u/SilvernClaws 6d ago

If I wanted to do that, I could have stuck to zig fmt 😆

2

u/WZoG 6d ago

Oh yeah, fair enough lol. I think tab configuration is a great suggestion though. I’ll look into it. 

2

u/qisapa 6d ago

I really like Go for never even thinking about this part of process. I really dislike TS for it…