Formatting
tcm formats with oxfmt. Nothing to install or configure. Formatting never changes a hash: whitespace, layout, quotes and trailing commas aren't part of it. So tcm formats freely, without touching identity, history or dependencies.
- What's saved is formatted.
tcm addandtcm updatestore each definition as oxfmt formats it, sotcm view,tcm edit, pages and generated modules show one style. Your scratch file is left as you wrote it. A mirrored codebase is the exception: its code is stored as its files spell it. - In VS Code, a scratch file is formatted on save and by Format Document. Other editors: the language server
answers
textDocument/formattingandwillSaveWaitUntil. tcm fmt [namespace]reformats what's already stored, after a style change or an oxfmt upgrade. No hash changes and nothing is re-derived. The new layout is an entry in the branch's history, like a comment change (history).
$ tcm fmt ~ lib.greet ~ lib.shout reformatted 2 definition(s); no hashes changed
Formatting can't change meaning. Every formatted text is analyzed again and kept only if each definition hashes
exactly as before; otherwise tcm keeps the text as it was and says so. One case where oxfmt would: breaking a long
line of JSX text before an expression, it inserts {" "}, which gives React different children. A definition that
would change this way is saved as written (tcm add says which), and the rest of its file is formatted.
fmt.config
A definition at fmt.config holds oxfmt's options, which are Prettier's (printWidth, singleQuote, semi,
trailingComma, …; the full list):
// tcm: namespace fmt
export const config = { singleQuote: true, semi: false, printWidth: 100 };
Changing it changes how new code is saved. tcm fmt restyles what's already there.
oxfmt ships with tcm at the version tcm was tested with. tcm upgrade oxfmt@<range> picks another for the codebase,
installed in its cache and pinned in the lock like any package (tcm packages).