Skip to content

rainbow-fmt

Every shade of style. A code formatter that formats code your way.

rainbow-fmt is a highly configurable, pluggable code formatter for JSON, CSS, Python, JavaScript, TypeScript, HTML, Svelte, TOML, YAML, Markdown, SQL, and any other language someone cares to describe. Every formatting decision is an option; every option can be set to preserve, keeping whatever the author wrote. Formatted output is verified before it is written: the syntax tree and the comments must be unchanged, and formatting the result again must change nothing.

Quick start

pip install rainbow-fmt            # Python 3.12 or newer

rainbow-fmt format src/            # rewrite files in place
rainbow-fmt check .                # exit 1 if any file would change
rainbow-fmt diff config.json       # show the changes
rainbow-fmt infer .                # write the rainbow.toml that matches the project

Write the decisions down in rainbow.toml (or pyproject.toml [tool.rainbow], YAML, or package.json) in the project root:

preset = "rainbow:balanced"        # start from a preset (optional)

[core]
max_width = 100
indent_size = 2

[language.json]
object_wrap = "always"             # "preserve" | "fit" | "always"
align_values = true

Where to go

The code is on GitLab, the package on PyPI; the changelog lists every release.