Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@contractkit/prettier-plugin

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contractkit/prettier-plugin

Prettier plugin for ContractKit DSL

latest
Source
npmnpm
Version
0.11.2
Version published
Maintainers
1
Created
Source

@contractkit/prettier-plugin

A Prettier plugin that formats ContractKit .ck files. Idempotent: re-formatting an already-formatted file is a no-op.

Installation

pnpm add -D prettier @contractkit/prettier-plugin

Configuration

Add the plugin to your prettier config:

{
    "plugins": ["@contractkit/prettier-plugin"]
}

Prettier registers .ck as the ContractDSL language and applies the plugin automatically.

Usage

# Format all .ck files in your project
pnpm prettier --write "**/*.ck"

# Or via the editor integration of your choice

Most editors with a Prettier integration (VS Code, JetBrains, Neovim) pick the plugin up from your project's package.json automatically.

What it does

The printer round-trips the parser's AST back into canonical .ck source:

  • 4-space indentation (matches Prettier's default tabWidth)
  • Canonical modifier order on fields: override → deprecated → readonly|writeonly
  • Stable ordering of options block items, route bodies, and operation blocks
  • Inline # comment placement preserved on field/operation/status lines
  • Multi-base inheritance: contract C: A & B & { ... } with the inline block always last
  • Multi-line unions: a leading | is preserved on type aliases like contract X: A | B | C
  • Discriminated unions render as discriminated(by=field, A | B | C)
  • Options-level header globals (options { request/response: { headers } }) are emitted in their original un-merged form so the AST round-trips cleanly

The plugin honours Prettier's printWidth for line-wrapping decisions where applicable, but most CK constructs format to a fixed multi-line shape regardless of width.

Source layout

PathPurpose
src/index.tsPrettier plugin entry — parser + printer registration
src/print-ck.tsTop-level dispatcher; renders the options { ... } block
src/print-contract.tsRenders contract declarations and field blocks
src/print-operation.tsRenders operation declarations, params, query, headers, request/response
src/print-type.tsShared type-expression printer used everywhere a type appears
src/indent.tsIndentation constants and helpers

Keywords

contractkit

FAQs

Package last updated on 15 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts