Formatting Code - axnic/rtunk GitHub Wiki
rtunk fmt runs every enabled formatter on the files you changed and rewrites them in place.
rtunk fmtWithout arguments, rtunk fmt selects files the same way as
rtunk check: the files that differ from the
upstream merge base (or from HEAD without an upstream), including untracked files. Pass paths to
format specific files or directories, and --from <ref> to set the diff base.
$ rtunk fmt
▲ taplo done 1 file changed
REFORMATTED 1 file
c.toml
Checked 1 file with 1 linter in 0.1s
✔ 1 file reformattedWith nothing to format, rtunk prints rtunk: no files to format and exits 0. A fmt that
rewrites files also exits 0: reformatting is not an error.
fmt writes to the working tree only. It never stages anything, so review the result with
git diff and add what you want to keep.
--check (-n) reports the files that would change and leaves them untouched. It exits 1 when
any file needs reformatting, which makes it suitable for CI:
$ rtunk fmt --check
▲ taplo done 1 file would change
WOULD REFORMAT 1 file
c.toml
Checked 1 file with 1 linter in 0.0s
✖ 1 file would be reformatted
rtunk: rtunk: fmt --check found 1 file(s) needing reformattingA file that is partly staged has changes in both the index and the working tree. Because fmt
rewrites the working copy, formatting it could mix your staged and unstaged edits. rtunk skips such
files with a warning:
$ rtunk fmt
rtunk: skipping partially staged file /path/to/c.toml (use --force to format it)
rtunk: no files to formatAdd --force to format them anyway. The index is still left untouched.
fmt and check are separate on purpose: check reads files, fmt writes them.
| You want to | Run |
|---|---|
| Rewrite files with formatters | rtunk fmt |
| Know which files a formatter would change | rtunk fmt --check |
| Format, then lint the formatted files in one run | rtunk check --format-before-check |
Other flags (--format human|json, --filter, --exclude, --verify-stable, --jobs) are
listed in rtunk fmt. --format sarif is only available for
check; fmt refuses it with exit 1 before running anything.
Note
If a formatter reports warning: ... was reformatted again ... possible formatter instability,
run again with --verify-stable: rtunk then repeats the pass until the output stops changing.
-
Checking Code — lint your changes and combine with
--format-before-check -
Command Reference — every flag of
rtunk fmt - Ignoring Issues — suppress findings you accept