Format with dprint
dprint formats .vibe files via the vibelang package's dprint plugin. It projects .vibe to TypeScript, formats it with dprint's TypeScript plugin, and writes back VibeLang — so .vibe and .ts files share the same typescript style settings. Install the packages with Add VibeLang to an existing project first.
1. Install dprint
Use dprint 0.64.3 or later (0.50.2 cannot resolve npm:vibelang/dprint-plugin.json):
npm install --save-dev dprint@0.64.32. Configure dprint.json
Add vibe to includes and npm:vibelang/dprint-plugin.json to plugins alongside dprint's TypeScript plugin:
{
"includes": ["**/*.{ts,vibe}"],
"excludes": ["**/node_modules", "**/dist", "**/*.d.ts", "**/*.d.vibe.ts", "**/*.d.vibex.ts"],
"lineWidth": 120,
"indentWidth": 2,
"typescript": {
"semicolons": "asi",
"quoteStyle": "alwaysDouble"
},
"plugins": [
"https://plugins.dprint.dev/typescript-0.97.1.wasm@3be85494ff8141c412535e659cbe3d764ed3a740375c929be48393ed20a9d429",
"npm:vibelang/dprint-plugin.json"
]
}- Why exclude declarations:
vibelangrewritesx.d.vibe.tsand forwardingx.d.tsfiles on every build (Let TypeScript tools read .vibe modules); formatting them causesdprint checkto fail after rebuilding. dprint already skips.gitignored paths like.vibe/declarations/, so projects usingvibe.sidecarDircan drop"**/*.d.ts"to format hand-written.d.tsfiles. - No plugin settings or checksum needed: dprint resolves
npm:vibelang/dprint-plugin.jsonfromnode_modules/vibelangand caches the checksummed native binary. Put all style options under"typescript". If your project requires explicit checksums on every plugin, runvibelang-format --writeafterdprint fmt(or--checkafterdprint check).
3. Format and check
npx dprint fmt
npx dprint checkdprint fmt rewrites unformatted files. dprint check writes nothing, prints diffs, and exits 20 if any file needs formatting (0 when clean).
CLI & marked TypeScript files
Use vibelang format (or vibelang-format) for .vibe, .vibex, and // @vibe-marked .ts/.mts/.cts/.tsx files — it inspects the directive before choosing a parser and uses TypeScript plugin 0.97.1 for .vibe and 0.93.4 for .vibex/marked .tsx:
npx vibelang format --check
npx vibelang format --write src/view.tsx- Exit status & selection:
--checkexits1when formatting is needed and writes nothing;--writeupdates files; the two flags cannot be combined. Unmarked TypeScript files are untouched. - Ignored files: The default scan, a directory argument and a glob pattern skip files that a
.gitignorefile ignores, including nested.gitignorefiles and those of parent directories, as dprint's own scan does. A file named on the command line is formatted even when ignored, as withvibelang format --check src/x.gen.vibe. - Paths vs. globs: An existing literal path (e.g.
'src/[id]/page.vibe') is selected before glob expansion. Missing explicit files, unmatched explicit globs, and unknown options fail before writing any file (a default scan with no matches succeeds). Use--before paths starting with-. - Caching: Unchanged files are cached per quote style, width, and syntax kind so clean checks skip launching dprint. Control with
VIBELANG_DISABLE_CACHE=1andVIBELANG_CACHE_DIR.
What the formatter changes
dprint's TypeScript rules control indentation, lineWidth wrapping, quotes, semicolons, and trailing commas while preserving import/re-export and specifier order. VibeLang forms format as follows:
| Form | Formatting rule |
|---|---|
A!E!R, when / is patterns | Kept as written; is stays on the same line as its subject and pattern start |
match (x) { when P: v; ... } | One line if written on one line and fits; otherwise one ;-terminated arm per line |
provide X { ... }, uninterruptible { ... } | Block statement; provide list never wraps between providers and { stays on the final provider's line |
x catch (e) => y, x |> f(%) | Line breaks before catch or |> are preserved |
fork x, join x, throw x | Prefix operator spacing (fork.in(scope)work() → fork.in(scope) work()) |
error, schema, data | Object-type body (one line if it fits); comma field separators preserved; empty ; members without JSDoc may be removed |
service | Class body, one member per line; comma separators preserved |
(do { ... }), statement match, labeled arrows | Grouping, braces, and leading ; under ASI preserved to keep parse structure and completion values |
| Parenthesized return types & computed keys | Written parentheses and enclosed comments kept (e.g. (): (() => string), [(key)]) |
JSX (.vibex) | Formatted via TSX formatter; preserves JSX text ({" "}), entities, comments, x as T, and <T,>(x: T) => x |
Semantic preservation guarantees
Under the same compiler and options, formatting is idempotent and preserves:
- Program semantics: parsed program meaning, evaluation order, receivers, ordinary runtime values/effects, public types/declarations/throws contracts, and comments/JSDoc attachment (including
@internal,@throws, and standalone;with JSDoc). - Diagnostics: diagnostic codes, categories, and occurrences stay unchanged (locations and excerpts follow the formatted file); formatting never applies semantic repairs (e.g.
EK0101foreffect f()orEK4003for a recovered unnamed top-levelmodule { ... }stay intact). - Allowed byte changes: quote, grouping, comma, and layout styling may change emitted JavaScript bytes,
Function.prototype.toString, offsets, and stack presentation, and refreshes source-map/declaration-map provenance includingsourcesContent. Ordinary strings/data, tagged-template raw/cooked values, regex meaning, function names/lengths, property names, and directive semantics (an escaped string never becomes ause strictdirective) remain unchanged.
What the formatter refuses
The formatter leaves a file untouched (with its original path in the error message) when:
- Syntax errors exist (
vibelang format: line:column: message), including amatcharm missing;(EK0701). - JSDoc/metadata attachment would change (such as an inline
/* @internal */comment attaching to or detaching from a field, method, or accessor). - Program meaning would change (a formatter bug — report it with the file).
Comments between ordinary TypeScript try/catch/finally clauses are supported, as are comments between catch and a literal handler, comments between effect/do and {, and U+2028/U+2029 line separators.
Editor, Prettier, and checkout builds
- Shared formatter (VIP-34): The language server (
formatting,rangeFormatting,onTypeFormatting),vibelang format,vibelang-format, andvibelang/prettierall share one formatter. They read the nearest Oxfmt, Prettier, ordprint.jsonconfig (defaulting to double quotes, width 120), reuse the locally installed native binary without npm downloads, and format Prettier buffers directly even if path-ignored (Developer tools). - From a VibeLang checkout:
sh scripts/build-vibelang.shbuilds the compiler and writespackages/compiler/dprint-plugin.jsonbeside it (vibelang --write-dprint-plugin <dir>writes it elsewhere).