Integrations¶
How to run rainbow-fmt from the tools around a project: pre-commit, CI, editors (TASKS.md T31–T33).
pre-commit¶
.pre-commit-hooks.yaml defines two hooks.
rainbow-fmt rewrites the staged files (so the commit fails once, with
the files reformatted, and goes through on the second try); rainbow-fmt-check
only reports:
# .pre-commit-config.yaml
repos:
- repo: https://gitlab.com/thebjorn/rainbow-fmt
rev: v0.3.0
hooks:
- id: rainbow-fmt
The hooks run on the extensions of the built-in packs. For a plugin pack
(say .scm), add its files to the hook:
- id: rainbow-fmt
files: \.(py|scm)$
additional_dependencies: [rainbow-lang-scheme]
GitHub Actions¶
action.yml is a composite action that installs
rainbow-fmt and runs rainbow-fmt check (or diff) on the given paths;
the job fails when a file would change or cannot be formatted:
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: thebjorn/[email protected]
with:
paths: src tests
command: diff # show the changes in the log (default: check)
version: "==0.3.0" # a PyPI version specifier (default: the latest)
The action needs the repository mirrored on GitHub to be referenced by
uses:; from GitLab CI, or anywhere else, the two lines it runs are
enough:
format:
image: python:3.12-slim
script:
- pip install rainbow-fmt
- rainbow-fmt check --no-cache src tests
--no-cache is not needed for correctness (the cache is keyed on the
file's content, options and rainbow-fmt's own version) but saves writing a
cache that a fresh CI job will never read.
Editors¶
rainbow-fmt lsp is a language server for document formatting
(lsp.md); the VS Code extension in
editors/vscode runs it. Any editor with
an LSP client can be pointed at the command directly.