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¶
- Overview: the problem, the idea, the principles.
- Command line and configuration: the commands, the option vocabulary, presets, overrides and directives.
- Integrations: pre-commit, GitHub Actions, editors; the language server behind the VS Code extension.
- One page per language, from CSS to SQL, with the options each pack adds.
- How to implement a style guide as a configuration, and how to define a language module of your own.
- Architecture, the Doc IR and extending, for the internals.
The code is on GitLab, the package on PyPI; the changelog lists every release.