Skip to content

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.

vibelang format with dprint

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.3

2. 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: vibelang rewrites x.d.vibe.ts and forwarding x.d.ts files on every build (Let TypeScript tools read .vibe modules); formatting them causes dprint check to fail after rebuilding. dprint already skips .gitignored paths like .vibe/declarations/, so projects using vibe.sidecarDir can drop "**/*.d.ts" to format hand-written .d.ts files.
  • No plugin settings or checksum needed: dprint resolves npm:vibelang/dprint-plugin.json from node_modules/vibelang and caches the checksummed native binary. Put all style options under "typescript". If your project requires explicit checksums on every plugin, run vibelang-format --write after dprint fmt (or --check after dprint check).

3. Format and check

npx dprint fmt
npx dprint check

dprint 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: --check exits 1 when formatting is needed and writes nothing; --write updates 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 .gitignore file ignores, including nested .gitignore files and those of parent directories, as dprint's own scan does. A file named on the command line is formatted even when ignored, as with vibelang 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=1 and VIBELANG_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:

FormFormatting rule
A!E!R, when / is patternsKept 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 xPrefix operator spacing (fork.in(scope)work() → fork.in(scope) work())
error, schema, dataObject-type body (one line if it fits); comma field separators preserved; empty ; members without JSDoc may be removed
serviceClass body, one member per line; comma separators preserved
(do { ... }), statement match, labeled arrowsGrouping, braces, and leading ; under ASI preserved to keep parse structure and completion values
Parenthesized return types & computed keysWritten 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. EK0101 for effect f() or EK4003 for a recovered unnamed top-level module { ... } 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 including sourcesContent. Ordinary strings/data, tagged-template raw/cooked values, regex meaning, function names/lengths, property names, and directive semantics (an escaped string never becomes a use strict directive) 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 a match arm 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, and vibelang/prettier all share one formatter. They read the nearest Oxfmt, Prettier, or dprint.json config (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.sh builds the compiler and writes packages/compiler/dprint-plugin.json beside it (vibelang --write-dprint-plugin <dir> writes it elsewhere).