unibeautify; dprint; jqfmt
Code formatting can be a crucial aspect of software development. Adhering to a formatting convention can help ensure consistency and readability across projects. Unfortunately, if you end up code-switching during the day/week/month, you may find that you need to rely on language-specific/single-purpose formatters. This also means having to manage and master multiple formatters for different languages. To say the least, this can be cumbersome.
So, today, we look at two multi-purpose formatters with different approaches to said formatting paradigm, and a relatively new-kid-on-the-block single-purpose formatter for jq programs.
TL;DR
(This is an AI-generated summary of today’s Drop using Perplexity with the Claude 3.5 sonnet model.)
I am really liking the combo of Perplexity and Sonnet.
jqfmt (https://github.com/noperator/jqfmt): A new, opinionated formatter specifically for jq programs, applying consistent formatting rules to improve readability and maintainability of complex jq code.
Unibeautify (https://unibeautify.com/): A universal interface for code formatters and linters, supporting over 20 programming languages with extensive configuration options and GitHub automation capabilities.
dprint (https://github.com/dprint/dprint): A Rust-based, pluggable code formatter using WASM modules for language support, offering fast performance and granular control over formatting rules across multiple languages.
unibeautify

Unibeautify (GH) acts as a universal interface for various code formatters and linters. It supports over 20 programming languages, including JavaScript, Python, C++, and Go. The system lets us configure multiple beautifiers for each language, enabling fine-grained control over code style.
This tool does not perform any formatting itself. Instead, it manages underlying beautifiers and provides a consistent configuration and incantation experience. This approach simplifies managing the configurations and operations of existing tools while benefiting from a unified configuration and execution process.
It has over forty configuration parameters, and we can tailor the formatting process to match any project’s specific requirements. The system also generates up-to-date documentation automatically, so we can keep up with the latest information on beautifiers, languages, and options.
There’s also a very decent VS Code|Codium extension, but the CLI works just fine for me (this also makes formatting ops less-IDE-specific).
The project’s GitHub automation capabilities are particularly noteworthy. Unibeautify can automatically format code on each push, providing a report via GitHub’s Checks API. This feature lets teams to maintain consistent code style without manual intervention. It’s still in private beta, but there’s nothing stopping you from using the CLI-based tooling and making a basic CI formatter on your own.
The devs also made the tool pretty modular, so we can create custom beautifiers to support additional languages or formatting styles. The project maintains a growing ecosystem of beautifiers, including popular tools like Prettier, ESLint, and clang-format.
The tools likely isn’t very useful if you just code-switch between a couple languages, but it can truly help reduce cognitive load if you do juggle a bunch of them, regularly.
dprint

Dprint is a Rust-based FOSS project that offers a pluggable and configurable solution to the aforementioned common challenge of needing to format code from multiple languages. This dprint devs have come up with a pretty flexible approach to code formatting that supports multiple programming languages through a plugin interface.
A super cool feature of dprint is that plugins are just WASM modules! So, you can make new plugins in any language that can compile to WASM. They can be imported from URLs or local file paths, which makes it pretty straightforward to both distribute them and integrate them into your projects/processes. For languages that cannot be compiled to WASM, dprint also supports process plugins, which run as separate executables.
The TypeScript/JavaScript plugin, a robust component of dprint, leverages the Rust-based SWC parser, and is blazing fast. This plugin supports not only TypeScript and JavaScript, but also JSX and TSX, finally bringing peace to warring front-end development team members.
The configuration system affords granular control over formatting rules, and we can (as one would expect) fine-tune settings such as line width, indentation, and newline preferences. The platform also respects explicit newlines in certain contexts (lack of which is a pet peeve of mine for various other formatters), preserving intentional code structure while still enforcing consistent formatting.
To experience dprint without sullying your system, you can kick the tyres in their online playground. Go crazy experimenting with different formatting options and see the output in real-time. Dprint also integrates well with popular code editors through extensions.
Additional plugins support formatting for JSON, Markdown, TOML, and other file types; and dprint even provides wrappers for existing formatters like Prettier and Biome.
But wait…there’s more! Dprint also has the ability to share and reuse configurations via URLs so you can maintain uniform formatting standards across teams and repositories.
It’s a very neat project that’s (IMO) worth investigating, even if you only code-switch between a couple languages.
jqfmt

There’s a new tool in town focused solely on formatting jq programs. If you only use short jq CLI incantation, you may not be fully aware that it truly is a robust programming language in-and-of itself. Complex jq programs can be pretty extensive, and the language syntax, combined with the way one deals with JSON paths, can make structuring the formatting of various bits fairly challenging.
jqfmt will apply opinionated, consistent formatting rules to jq code. It reminds me quite a bit of how opinionated gofmt or caddy fmt is for Go code and Caddy configs (respectively).
Some key features:
- automatic indentation based on nesting level
- consistent placement of line breaks and spaces around operators
- wrapping of long lines to improve horizontal readability
- preservation of comments and overall script structure (yes, you can, and should, comment
jqcode)
The tool works well in pre-commit hooks, and there are fledgling editor plugins for it as well.
Early adopters report significant improvements in code clarity and maintainability. We’ll likely be using it pretty heavily at work with a new jq-based data pipeline we just set up.
As data processing pipelines grow more complex — and more reliant on the jq language — tools like jqfmt can play an important role in keeping code readable and maintainable, and pipelines more stable. Wider adoption could help establish consistent style conventions for jq, similar to those seen in other programming languages.
FIN
Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via @dailydrop.hrbrmstr.dev@dailydrop.hrbrmstr.dev ☮️
Leave a comment