New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dprint-cli

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dprint-cli

JavaScript implementation of dprint CLI for formatter

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
1
Created
Source

dprint-cli

A JavaScript implementation of the dprint CLI for code formatting. This tool provides the core functionality of dprint, allowing you to format source code files using dprint's plugin system.

Usage

# install with your package manager
bun add -D dprint-cli @dprint/{typescript,json}
npm install -D dprint-cli @dprint/{typescript,json}

# or run directly
bunx dprint-cli
npx dprint-cli

Features

  • Multiple Language Support: Format TypeScript, JavaScript, JSON, and Markdown files
  • Plugin System: Load formatters from npm packages
  • Configuration: Uses dprint.json for configuration with include/exclude patterns
  • Three Main Commands:
    • init - Initialize a new configuration file
    • fmt - Format files and write changes
    • check - Check if files are formatted correctly
  • Rust dprint Compatibility: Exit codes and behavior match the official Rust dprint CLI

Installation

First, install the dependencies:

npm install

Make the CLI executable:

chmod +x bin/dprint

Optionally, link it globally:

npm link

Usage

Initialize Configuration

Create a new dprint.json configuration file in the current directory:

node bin/dprint init

Format Files

Format all files according to the configuration:

node bin/dprint fmt

Format specific files or patterns:

node bin/dprint fmt src/**/*.ts
node bin/dprint fmt -- src/**/*.ts test/**/*.js

Check Formatting

Check if files are formatted correctly without modifying them:

node bin/dprint check

Check specific files:

node bin/dprint check src/**/*.ts

Configuration

The dprint.json file configures which files to format and how. Example:

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "projectType": "openSource",
  "incremental": true,
  "includes": ["**/*.{ts,tsx,js,jsx,json,md}"],
  "excludes": [
    "**/node_modules",
    "**/*-lock.json",
    "**/dist",
    "**/build",
    "**/coverage"
  ],
  "plugins": [
    "@dprint/typescript",
    "@dprint/json",
    "@dprint/markdown"
  ],
  "typescript": {},
  "json": {},
  "markdown": {}
}

Plugin Configuration

Plugins are loaded from your node_modules directory. Make sure to install the required plugins:

npm install @dprint/typescript @dprint/json @dprint/markdown

The plugins in dprint.json should match npm package names installed in your project.

How It Works

  • Configuration Discovery: Searches for dprint.json starting from the current directory and walking up the directory tree
  • Plugin Loading: Dynamically imports formatter plugins from npm packages
  • File Discovery: Uses glob patterns to find files matching include patterns while excluding specified patterns
  • Formatting: Loads WASM formatters and applies them to matching files

Example Workflow

# 1. Initialize project
node bin/dprint init

# 2. Install formatter plugins
npm install @dprint/typescript @dprint/json @dprint/markdown

# 3. Format your code
node bin/dprint fmt

# 4. Check formatting in CI
node bin/dprint check

CLI Options

USAGE:
    dprint <SUBCOMMAND> [OPTIONS] [--] [file patterns]...

SUBCOMMANDS:
    init     Initializes a configuration file in the current directory
    fmt      Formats the source files and writes the result to the file system
    check    Checks for any files that haven't been formatted
    help     Shows this help message

OPTIONS:
    --       Treat all following arguments as file patterns

Testing

bun test

License

MIT

Keywords

dprint

FAQs

Package last updated on 24 Nov 2025

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