// guide

Configuration

Configuration allows you to modify how kprint and its plugins behave.

Setup

See Setup.

Example

{
  "lineWidth": 80,
  "typescript": {
    // This applies to both JavaScript & TypeScript
    "quoteStyle": "preferSingle",
    "binaryExpression.operatorPosition": "sameLine"
  },
  "json": {
    "indentWidth": 2
  },
  "excludes": [
    "**/*-lock.json"
  ],
  "plugins": [
    // You may specify any urls or file paths here that you wish.
    "https://plugins.dprint.dev/typescript-x.x.x.wasm",
    "https://plugins.dprint.dev/json-x.x.x.wasm",
    "https://plugins.dprint.dev/markdown-x.x.x.wasm"
  ]
}

Remote plugin configuration

A plugin that declares configuration-file support can use an HTTP(S) URL:

{
  "toml": {
    "configFile": "https://example.com/formatting/tombi.toml"
  }
}

In a remote kprint configuration, configFile = "./tombi.toml" resolves beside that configuration's URL. Relative extends and plugin URLs work the same way. After a redirect, kprint uses the destination URL. ${configDir} expands to that URL's directory, and ${originConfigDir} refers to the main configuration's directory.

Kprint caches downloaded configuration files. Plugins can declare references to other configuration files and schemas, which kprint also downloads and supplies to the plugin. The plugin applies its own inheritance rules. Remote files cannot request local files through these references.

TOML

The configuration file may also be TOML: kprint.toml or .kprint.toml, or dprint.toml or .dprint.toml. A directory's kprint files take precedence over its dprint files, and for each prefix the TOML file takes precedence over the JSON one. The example above as TOML:

#:schema https://dprint.kjanat.dev/schemas/v0.json
lineWidth = 80
excludes = ["**/*-lock.json"]
plugins = [
  "https://plugins.dprint.dev/typescript-x.x.x.wasm",
  "https://plugins.dprint.dev/json-x.x.x.wasm",
  "https://plugins.dprint.dev/markdown-x.x.x.wasm",
]

# This applies to both JavaScript & TypeScript
[typescript]
quoteStyle = "preferSingle"
"binaryExpression.operatorPosition" = "sameLine"

[json]
indentWidth = 2

Property names with a dot in them are quoted, like they are in JSON. Arrays of objects (ex. "overrides" or the exec plugin's "commands") are arrays of tables, ex. [[exec.commands]].

Create one with kprint init --config kprint.toml. Commands that edit the configuration (ex. kprint add and kprint config update) keep its comments and layout. A configuration can extend a TOML file and vice versa (see extending), and --config also takes TOML text.

Schema

kprint schema prints a JSON schema of the configuration file that includes each plugin's configuration, so an editor can validate and complete the plugins' properties too. Save it next to the configuration file and refer to it:

kprint schema > kprint.schema.json
#:schema ./kprint.schema.json

In a JSON configuration file, that's "$schema": "./kprint.schema.json". Any editor or language server that reads JSON schemas can use it (ex. tombi for TOML). The plugins' schemas are versioned, so when there's a kprint.schema.json, or else a dprint.schema.json, next to the configuration file, kprint add, kprint config update and kprint init (when it adds plugins to an existing configuration file) regenerate it. After kprint add --package-json, that's with the version added to package.json, before it's installed.

That's done once the configuration file (and package.json) is changed, and takes at most about 30 seconds, downloads included. When a plugin's schema can't be retrieved (ex. its download fails, it's over 8 MiB, or it isn't valid JSON), or it takes longer, the schema file is kept as it was rather than replaced with one missing that plugin's configuration, and kprint warns about it. The configuration file stays changed either way. Likewise, kprint schema errors rather than prints a schema without a plugin whose schema it couldn't retrieve, unless --allow-incomplete is specified.

The schema describes one configuration file, so it doesn't require what another file may provide (ex. the commands of an extended configuration). For a configuration file that inherits ("inherit": true), it includes the plugins it inherits, from the configuration file of the closest ancestor directory with one (or else the global configuration file).

The schema is JSON schema 2020-12, which bundles schemas by embedding each as a resource of its own: each plugin's schema is under $defs, keeping its $id (or getting the url it was downloaded from as one) and its references, which are resolved against that as in the plugin's own document. Where a plugin's schema is of an earlier draft (draft-04 to 2019-09), the syntax that draft had for the same thing is translated (ex. an items array becomes prefixItems, and what a draft before 2019-09 ignored next to a $ref is dropped); a schema of a draft kprint doesn't know is referred to by its url instead, which kprint schema warns about, as editors may then report kprint's own properties of that plugin's table (ex. associations) as unknown. The same goes for a plugin schema whose table is described by another file (ex. a $ref to another url). What's under a keyword that isn't JSON schema's (ex. an editor extension's x- keyword) is kept as it is.

A plugin's schema describes the plugin's own properties: what kprint hands the plugin is its table without associations, locked and overrides, and each override without files. So its properties apply in the table, and in each override (where nothing is required) as far as the schema declares them unconditionally: what it says on a condition (ex. in an anyOf branch) isn't checked in an override, as the table the override is merged into decides the condition. A plugin schema that describes its table as a whole (ex. with maxProperties or propertyNames), which can't say what it does of that, isn't applied at all. kprint schema warns about both.

kprint's own part of the schema (the configuration file's properties, and what every plugin's table has) is generated from the types kprint reads a configuration file into, so what kprint accepts and what the schema says are one definition. The schema of the built-in exec plugin is generated the same way from what it reads its configuration into, and comes with kprint rather than being downloaded, so it describes what this version accepts (ex. playWithFire and setupTimeout).

The TOML plugin puts a space after the # of every comment by default, which turns #:schema into # :schema, a comment tombi doesn't read. Either set "comment.forceLeadingSpace": false in the toml configuration, or give the file its schema in tombi.toml instead:

[[schemas]]
path    = "kprint.schema.json"
include = ["kprint.toml"]

Plugins

The plugins property specifies which plugins to use for formatting. These may be URLs or file paths to a WebAssembly file of the plugin.

{
  // ...omitted...
  "plugins": [
    // You may specify any urls or file paths here that you wish.
    "https://plugins.dprint.dev/typescript-x.x.x.wasm",
    "https://plugins.dprint.dev/json-x.x.x.wasm",
    "https://plugins.dprint.dev/markdown-x.x.x.wasm"
  ]
}

Alternatively, these may be provided to the CLI via the --plugins <plugin urls or file paths...> flag.

Note: The order of the plugins in this array defines the precedence. If two plugins support the same file extension then define the one you want to format that extension with first. For more fine grained control, see "associations" below.

Adding Plugins via CLI

You may add a plugin via the CLI by running:

kprint add

This will prompt asking you which of the standard plugins you want to add.

Alternatively, specify the specific name of the plugin to add based on its GitHub repo:

kprint add dprint/dprint-plugin-typescript

Or for the standard plugins, you can just do:

kprint add typescript

You can also add multiple plugins at once:

kprint add typescript json markdown

Or specify a plugin url:

kprint add https://plugins.dprint.dev/json-x.x.x.wasm

Or from npm:

kprint add npm:@dprint/json

By default Wasm plugins are added without a checksum (process plugins always get one). Use --checksum to pin a checksum on the added plugin regardless:

kprint add --checksum typescript

Note: kprint config add also works and is equivalent.

Minimum Dependency Age

For plugins on npm, you can specify a --minimum-dependency-age:

kprint config update --minimum-dependency-age=P3D

The value takes the following forms: an ISO-8601 duration (P3D, PT72H), a plain number of minutes (1440), an absolute date (2026-01-15) or RFC3339 timestamp to hold back everything published after it, or 0 to turn the requirement off.

With no flag, kprint uses the configuration file's minimumDependencyAge, which takes the same forms:

{
  "minimumDependencyAge": "P3D"
}

The flag takes precedence, so --minimum-dependency-age=0 turns a configured age off for one run. There is no minimum otherwise — a version is only ever held back when you ask for one. Some other notes:

  • It applies to npm-distributed plugins and npm configurations updated through extends. References served from a URL carry no publish date for kprint to check.
  • It never downgrades an entry you already have. Existing plugin versions are left alone, and a version you write out yourself (kprint config add npm:@dprint/json@1.2.3) is taken as your decision and added as-is — so an explicit version is a way to opt a single plugin out.
  • Only stable releases at or below the package's latest tag are considered when walking back, so a prerelease can't be selected by a walk back you didn't ask for. A package whose latest tag is itself a prerelease walks back through prereleases, since that's all it has.
  • kprint config update leaves a plugin where it is when no version of its package is old enough, reporting it rather than failing. kprint init and kprint config add error in the same situation, since there's nothing to write.

Updating Plugins and Shared Configurations via CLI

Use this command to update plugins and versioned npm: entries in extends.

kprint config update

To update configuration files in descendant directories, run kprint config update --recursive.

In a terminal, choose which updates to apply. Process plugin updates and checksum-pinned extends still ask for confirmation. Run kprint config update --yes to apply all available updates without prompting, or kprint config update --dry-run to preview the changes without writing project configuration or schema files. On a cold cache, the preview may download and extract replacement packages into the cache.

When an extends entry updates, its subpath is kept and its checksum is refreshed if it has one. Your package manager still manages unversioned npm: entries.

Using Plugins from npm

Plugins can be referenced by npm specifiers instead of HTTPS URLs. This is useful in environments where downloading from plugins.dprint.dev or other domains is restricted, or when you're already using npm and want one place to download dependencies from.

Supported npm: specifier forms:

{
  "plugins": [
    // resolve a pinned version from the npm registry (wasm plugin)
    "npm:@dprint/typescript@0.95.15",

    // process plugin — requires a tarball checksum
    "npm:@dprint/prettier@0.50.0/plugin.json@<sha256>",

    // a plugin that isn't at the root of its package
    "npm:@dprint/example@1.0.0/json/plugin.wasm",

    // resolve from your local node_modules, walking up from the config file
    // (use this when an npm package manager manages the version)
    "npm:@dprint/json",
  ],
}

Behaviour:

  • A version after @ makes kprint download the plugin and cache it. A Wasm plugin without a checksum comes straight from jsDelivr (https://cdn.jsdelivr.net/npm/<name>@<version>/<path>). A checksum covers the package tarball, so a checksummed reference and a process plugin download the tarball from registry.npmjs.org and verify it. Wasm plugins don't need a checksum; process plugins do (the @<sha256> after the path).
  • Omitting the version (npm:@scope/name) tells kprint to look up the package in node_modules walking up from the config file's directory. Use this when you want npm and your lockfile to be the source of truth.
  • kprint config update will bump versioned npm specifiers to the latest published version (and compute the new checksum for process plugins). The latest version comes from jsDelivr's package API (https://data.jsdelivr.com/v1/packages/npm/<name>/resolved?specifier=latest). A minimum dependency age needs publish times, so it reads the package's metadata from registry.npmjs.org instead. Unversioned specifiers are managed by your package manager, so they're skipped. See Minimum Dependency Age to hold off on npm dependencies that are only days old.
  • A plugin referenced by URL moves to npm only when its own update metadata declares an npm package. A matching plugin name in the global registry does not authorize a migration, even when both plugins use the same hostname. Without that declaration, the plugin continues to update through its own update URL.
  • kprint add npm:@scope/name resolves to the latest version and writes the pinned form, unless the package is listed in a nearby package.json under devDependencies — in which case the unversioned form is written so npm/package-lock.json stays the source of truth. When you don't include a plugin path, kprint inspects the package to detect whether it's a Wasm or process plugin and writes the right form automatically — for a process plugin that means npm:@scope/name@<version>/plugin.json@<sha256>.

Available npm packages include @dprint/typescript, @dprint/json, @dprint/markdown, @dprint/toml, @dprint/dockerfile, @dprint/biome, @dprint/oxc, @dprint/ruff, @dprint/sql, @dprint/mago, @dprint/jupyter, @dprint/exec, @dprint/prettier, and @dprint/roslyn.

You can also reference a plugin file directly in node_modules if you prefer ("./node_modules/@dprint/typescript/plugin.wasm"); the npm: form just removes the need for that path.

Process plugins distributed via npm

A process plugin's plugin.json lists per-platform binaries; for npm-installed process plugins the reference field must be one of:

  • a relative path ("./bin.zip") or file:///… URL — resolved against the plugin.json's directory inside the npm package. This is the simplest layout: ship plugin.json and bin.zip together in one npm package.
  • an npm: specifier — used when the per-platform binary lives in a separate npm package (e.g., the manifest references npm:@scope/foo-linux-x86_64@1.0.0/plugin.zip and the dep is installed alongside via npm optionalDependencies).

http:// and https:// references are rejected for npm-installed process plugins. The whole point of installing via npm is to avoid surprise network fetches at format time, so the binary must come from the npm package(s) you already installed.

Cache layout

Resolved npm packages are extracted under <kprint-cache>/npm/registry.npmjs.org/<name>@<version>/. Compiled wasm modules and extracted process-plugin binaries continue to live under <kprint-cache>/plugins/. kprint clear-cache wipes everything.

Editing Config via CLI

kprint config edit

Editing the configuration file will use the editor configured in the DPRINT_EDITOR environment variable, then VISUAL, then EDITOR. If none of these environment variables are set, it will launch notepad on Windows and nano elsewhere.

Excludes

The excludes property specifies the file paths exclude from formatting.

These should be file globs according to gitignore's extended glob syntax:

{
  // ...omitted...
  "excludes": [
    "**/*-lock.json"
  ]
}

Un-excluding gitignored files

Files that are gitignored will be excluded by default, but you can "un-exclude" them by specifying a negated glob:

{
  "excludes": [
    // will format dist.js even though it's gitignored
    "!dist.js"
  ]
}

Alternatively, you can disable all .gitignore handling with the --no-gitignore CLI flag (see CLI docs).

Escaping glob characters

To match a path that contains glob characters (ex. [ or {) in includes/excludes, wrap each one in a character class:

{
  "excludes": [
    // excludes a file named {{myfile}}.json
    "[{][{]myfile[}][}].json",
    // excludes a directory named [id]
    "routes/[[]id[]]"
  ]
}

Includes

The includes property can be used to limit kprint to only formatting certain files. Generally, you don't need to bother providing this.

{
  // ...omitted...
  "includes": [
    "src/**/*.{ts,tsx,js,jsx,json}"
  ]
}

Associations

By default, plugins will pull in files based on their extension. Sometimes a file may have a different extension or no extension at all, but you still want to format it with a certain plugin. The plugin "associations" config allows you to do that by associating a certain file pattern to one or multiple plugins.

For example:

{
  "json": {
    "associations": [
      // format any file named `.myconfigrc` matched by the
      // includes/excludes patterns in any directory with
      // the json plugin
      ".myconfigrc",
      // format this specific file using the json plugin
      "./my-relative-path/to-file",
      // format files that match this pattern
      "**/*.myconfig"
    ]
  },
  "plugins": [
    "https://plugins.dprint.dev/json-x.x.x.wasm"
  ]
}

Note that first the "includes"/"excludes" file resolution occurs and then the associations is used to map those files to a plugin. Specifying associations may also be useful for formatting a file with multiple plugins or forcing a file to be formatted with a specific plugin.

Associations are additive: the patterns you specify are matched in addition to the file extensions and file names the plugin matches by default. For example, a plugin that formats .json files by default will also format .myconfig files once "associations": ["**/*.myconfig"] is set—.json files keep being formatted. To stop matching a default extension or file name, use a negated glob (see below).

Excluding paths from plugin

A negated glob (!) is the way to stop a plugin from matching a file it would otherwise format by default—whether that's a default file extension, a default file name, or a path.

In the following example, both the TypeScript plugin and Prettier plugin support formatting .js and .ts files. Say we want to only format .ts files with the TypeScript plugin and .js files with the prettier plugin. To do that, we can place the typescript plugin to have higher precedence in the "plugins" array, then add an excludes for only !**/*.js. This will cause the TypeScript plugin to match based on the file extension for .ts files, but then be excluded from matching on .js files.

{
  "typescript": {
    "associations": [
      "!**/*.js" // don't format javascript files
    ]
  },
  "plugins": [
    "https://plugins.dprint.dev/typescript-x.x.x.wasm",
    // side note: check the docs for the latest version of this plugin
    "https://plugins.dprint.dev/prettier-0.13.0.json@dc5d12b7c1bf1a4683eff317c2c87350e75a5a3dfcc127f3d5628931bfb534b1"
  ]
}

Shebangs

Scripts on POSIX systems often have no file extension and are identified only by their shebang (ex. #!/usr/bin/env bash). The "shebangs" config maps a shebang line to a file extension so these files get picked up by the plugin that handles that extension.

{
  "shebangs": {
    "#!/bin/sh": "sh",
    "#!/usr/bin/env bash": "sh",
    "#!/usr/bin/env deno run": "ts"
  }
}

With the above, a file named build starting with #!/bin/sh is formatted as if it were a .sh file. Some notes:

  • It only applies to files that have no extension and didn't otherwise match a plugin (a plugin's "associations" still win, and a negated association pattern is checked against the file's real path). A plugin that handles the mapped extension must be in the "plugins" list, otherwise the file is skipped.
  • A configured shebang matches when the file's first line equals it or starts with it followed by whitespace, so #!/usr/bin/env deno run matches #!/usr/bin/env deno run --allow-read but not #!/usr/bin/env deno runtest. When multiple entries match, the longest one wins. #!/usr/bin/env -S deno run is a different line, so list it separately if you use it.
  • Extensionless files are checked for a matching shebang regardless of the config file's "includes" patterns. Negated include patterns, "excludes", gitignore, and file patterns provided on the command line (including --includes-override) still apply.
  • kprint only reads the first line of extensionless files to check for a shebang.
  • When using "extends", the shebangs are merged with the extending config's entries taking precedence. A nested config inherits them with "inherit": true unless it specifies its own.

Overrides

The plugin "overrides" config changes plugin configuration for specific files that are already formatted by that plugin.

For example:

{
  "json": {
    "overrides": {
      "files": ["**/package.json", "**/composer.json"],
      "indentWidth": 4,
      "useTabs": false
    }
  },
  "plugins": [
    "https://plugins.dprint.dev/json-x.x.x.wasm"
  ]
}

For multiple overrides, change it to an array:

{
  "json": {
    "overrides": [
      {
        "files": ["**/package.json", "**/composer.json"],
        "indentWidth": 4,
        "useTabs": false
      },
      {
        "files": "**/special-package.json",
        "lineWidth": 80
      }
    ]
  },
  "plugins": [
    "https://plugins.dprint.dev/json-x.x.x.wasm"
  ]
}

Each override must specify a "files" pattern or list of patterns. All other properties in the override except "embedded" (see Embedded Code) are plugin configuration properties.

Note that "overrides" only changes configuration. It does not include files, exclude files, or associate files with a plugin. File discovery still uses the top-level "includes" and "excludes" settings, and plugin routing still uses the plugin's supported file names, file extensions, and "associations".

When multiple override blocks match the same file, they are applied in order and later values win.

Embedded Code

Some plugins format code embedded in a file by handing it back to kprint, ex. the markdown plugin with the code blocks of a .md file. kprint formats that code with the plugin that formats the code's file extension. The plugin's "embedded" config names the plugins to format it with instead, by the code's file extension, in order. An empty array leaves that code as it is.

{
  "markdown": {
    // C# code blocks are formatted with exec, and SQL code blocks are left as they are
    "embedded": { "cs": ["exec"], "sql": [] },
    "overrides": {
      // except in README.md, whose TypeScript code blocks are left as they are too
      "files": "README.md",
      "embedded": { "ts": [] }
    }
  },
  "exec": {
    "commands": [{ "command": "dotnet csharpier --write-stdout", "exts": ["cs"] }]
  }
}
  • The extension is the one the plugin gives the code. The markdown plugin gives it from the code block's tag (ex. csharp and cs are both cs), and its "tags" config maps other tags.
  • A plugin named in "embedded" must be in the configuration. It formats the code whatever file extensions it formats by default.
  • An override's "embedded" applies to the code in the files the override matches. The last matching override that names the code's file extension wins, otherwise the plugin's own "embedded" does.
  • "extends" merges "embedded" by file extension, with the extending config's entries taking precedence.

Shell examples and placeholders

A shell formatter treats <dialect> as shell redirection syntax. For example, formatting shellcheck -s <dialect> -f gcc - may move those redirections and make the documentation's placeholder unreadable. Use text fences for pseudo-code, or put <!-- dprint-ignore --> immediately before a code fence to preserve that individual block.

To keep syntax highlighting while preserving sh and bash examples, disable embedded formatting for those extensions in the Markdown configuration:

{
  "markdown": {
    "embedded": { "sh": [], "bash": [] }
  }
}

Add an empty array for any other shell extension your configuration uses, such as "zsh": []. This also works in a local configuration that extends a shared configuration with a shell plugin. Standalone shell files still use that plugin. Other embedded languages retain their configured formatting behavior. For only selected Markdown files, put the same embedded setting in a matching Markdown override.

Shell blocks without an explicit opt-out continue to use the configured shell formatter. The host does not guess whether valid redirection syntax represents a documentation placeholder.

Extending a Different Configuration File

You may extend other configuration files by specifying an extends property. This may be a file path, URL, or relative path (remote configuration may extend other configuration files via a relative path).

{
  "extends": "https://example.com/path/to/config/file.v1.json",
  // ...omitted...
}

Referencing multiple configuration files is also supported. These should be ordered by precedence:

{
  "extends": [
    "https://example.com/path/to/config/file.v1.json",
    "https://example.com/path/to/config/other.v1.json"
  ]
}

An extended configuration file adds its plugins, plugin configuration, "excludes", "shebangs" and "incremental" where the configuration file that extends it doesn't specify them. Which files to format ("includes") and whether to inherit are up to the configuration file being used, so specifying them in an extended configuration file is an error. A file may be extended by more than one file (ex. a shared base), but a configuration file that extends itself, directly or through other files, is an error.

Unpinned remote configuration has restrictions: includes, negated excludes, associations reaching parent directories, and non-Wasm plugins are filtered. A local file that an untrusted remote configuration extends (for example, with a file:// URL) has the same restrictions. Local exec.playWithFire settings continue to allow remote exec commands, either for specific programs or for all programs.

Pinning and Trust

Append @ and the file's 64-character SHA-256 checksum to an extends reference to pin its contents. For example, use https://example.com/base.json@<sha256>, replacing <sha256> with the checksum of the exact file bytes. Local paths support the same syntax.

A checksum-pinned file extended by trusted configuration is trusted too: it may supply process plugins, exec commands, negated excludes, and parent-directory associations. Every file it extends must also have a checksum, including local files. A checksum selected by an untrusted remote file cannot grant trust. The existing rule that extended configuration cannot specify includes or inherit still applies.

kprint verifies every pin before using the configuration. If a cached remote file has the wrong checksum, it checks the server again and rejects the file if it still differs. Existing program allowlists continue to apply to unpinned remote configuration.

Caching of Remote Configuration

Remote configuration files are downloaded once and stored in kprint's cache directory. A cached file is used for an hour. The next time it is resolved after that, kprint checks its URL for changes, so a change to a configuration file pinned to a branch (ex. https://cdn.jsdelivr.net/gh/user/repo@master/kprint.json) can be picked up an hour after the last check, once the CDN serves the new content (see below). When the check fails (ex. no network), the cached copy is used and a warning is logged. A response marked Cache-Control: immutable promises not to change for its max-age, so kprint trusts it for that long instead of an hour (ex. jsdelivr serves URLs pinned to a tag or commit with a one year max-age, so those are not checked again for a year). Pin to a tag or commit when you want that.

To pick up a change immediately, run kprint clear-cache. Note that CDNs have their own caches, so a change to a branch may take longer to appear (ex. jsdelivr serves branch content from its edge cache for up to 12 hours, while raw.githubusercontent.com uses a much shorter cache lifetime).

Directory Specific Configuration

Useful for monorepos, you may place additional configuration files in descendant directories. When kprint searches for files to format, it stops descending into a directory once it discovers a configuration file there and uses that configuration file for the files in that subtree instead (see changing config discovery).

By default a nested configuration file is completely independent—it does not pick up the plugins or configuration of the ancestor configuration file:

// ./sub-project/kprint.json
{
  // only TOML files in ./sub-project will be formatted
  "plugins": [
    "https://plugins.dprint.dev/toml-x.x.x.wasm"
  ]
}

To instead inherit the plugins and configuration of the ancestor configuration file, specify "inherit": true:

// ./sub-project/kprint.json
{
  "inherit": true,
  "typescript": {
    // inherits the ancestor's TypeScript config, but overrides the indent width
    "indentWidth": 2
  }
}

When inheriting:

  • Plugins specified in the nested configuration file have precedence over the ancestor's plugins. Any plugins not specified are inherited from the ancestor.
  • Plugin configuration is merged with the nested configuration file winning on conflicts.
  • The ancestor's excludes are combined with the nested configuration file's excludes.
  • The ancestor's includes are not inherited.

Inheriting is opt-in (rather than opt-out) so that adding a configuration file higher up in the directory structure does not unexpectedly start affecting a nested configuration file.

Incremental

By default, kprint will only format files that have changed since the last time you formatted the code in order to drastically improve performance.

If you want to disable this functionality, you may specify the following in your kprint configuration file:

{
  // etc...
  "incremental": false
  // etc...
}

Alternatively, specify --incremental=false on the CLI:

kprint fmt --incremental=false

Global Configuration

There are certain non-language specific configuration that can be specified. These are specified on the main configuration object, but can be overridden on a per-plugin basis.

For example:

{
  "lineWidth": 160,
  "useTabs": true,
  "typescript": {
    "lineWidth": 80
  },
  "json": {
    "indentWidth": 2,
    "useTabs": false
  },
  "plugins": [
    // etc...
  ]
}

Note: kprint does not provide or enforce any defaults for the global configuration. The defaults are set on a per plugin basis. When a value is not provided, the plugin may choose to use its default.

lineWidth

The width of a line the formatter will try to stay under. Note that this limit will be exceeded in certain cases.

indentWidth

The number of spaces for an indent when using spaces or the number of characters to treat an indent as when using tabs.

newLineKind

The kind of newline to use.

  • auto - For each file, uses the newline kind found at the end of the last line.
  • crlf - Uses carriage return, line feed.
  • lf - Uses line feed.
  • system - Uses the system standard (ex. crlf on Windows).

useTabs

Whether to use tabs (true) or spaces (false).

Locking Configuration—Opinionated Configurations

You may want to publish your own opinionated configuration and disallow anyone using it from overriding the properties.

This can be done by adding a "locked": true property to each plugin configuration you wish to lock.

Note: When doing this, ensure you set all the global configuration values if you wish to enforce those.

Example

Say the following configuration were published at https://example.com/configs/my-config.json:

{
  "typescript": {
    "locked": true,
    "lineWidth": 80,
    "indentWidth": 2,
    "useTabs": false,
    "quoteStyle": "preferSingle",
    "binaryExpression.operatorPosition": "sameLine"
  },
  "json": {
    "locked": true,
    "lineWidth": 80,
    "indentWidth": 2,
    "useTabs": false
  }
}

The following would work fine:

{
  "extends": "https://example.com/configs/my-config.json",
  "myOtherPlugin": {
    "propertySeparator": "comma"
  },
  "plugins": [
    "https://plugins.dprint.dev/typescript-x.x.x.wasm",
    "https://plugins.dprint.dev/json-x.x.x.wasm",
    "https://plugins.dprint.dev/my-other-plugin-0.1.0.wasm"
  ]
}

But specifying properties in the "typescript" or "json" objects would cause an error when running in the CLI:

{
  "extends": "https://example.com/configs/my-config.json",
  "typescript": {
    "useBraces": "always" // error, "typescript" config was locked
  },
  "json": {
    "lineWidth": 120 // error, "json" config was locked
  },
  "myOtherPlugin": {
    "propertySeparator": "comma"
  },
  "plugins": [
    "https://plugins.dprint.dev/typescript-x.x.x.wasm",
    "https://plugins.dprint.dev/json-x.x.x.wasm",
    "https://plugins.dprint.dev/my-other-plugin-0.1.0.wasm"
  ]
}

Configuration Variables

kprint expands certain variables in the config:

  • ${configDir} - The current configuration's directory.
  • ${originConfigDir} - The original configuration's directory. Useful when the current config is being extended by another configuration file and you want the original directory.

For example, in a JSON value you might do "rustfmt --config-path ${configDir}/rustfmt.toml".

They're expanded in the values of a plugin's configuration and its overrides relative to the file they're written in, before it's combined with the configuration it extends or inherits.

This is useful to use in some scenarios like with dprint-plugin-exec because the CLI will only launch a single plugin for many configs and when resolving configs, the plugins have no concept of where that config was resolved from. Additionally, configs may resolve other configs and perhaps you want to use the directory of a configuration file that was extended.

Note: kprint will error for unknown configuration variables (ex. "${unknown}"). You can get around this by escaping the $ sign (ex. "\\${unknown}").

Plugin/Language Specific Configuration

Running kprint help will list the help urls for all the configured plugins in your configuration file. On those pages you can view the help information.

For information on the official plugins' configuration, see the plugins section.

Next step: CLI