Skip to main content
The deno fmt command formats source files using Deno’s opinionated code formatter based on dprint.

Usage

deno fmt [OPTIONS] [FILES]...

Basic Examples

# Format all supported files in current directory
deno fmt

# Format specific files
deno fmt src/main.ts

# Format multiple files
deno fmt src/ tests/

# Check if files are formatted (don't write)
deno fmt --check

# Format stdin
cat file.ts | deno fmt -

Supported File Types

Deno’s formatter supports:
  • TypeScript (.ts, .tsx, .mts, .cts)
  • JavaScript (.js, .jsx, .mjs, .cjs)
  • JSON (.json, .jsonc)
  • Markdown (.md, .markdown)

Check Mode

--check
boolean
Check if files are formatted without writing changes
# Check formatting
deno fmt --check

# Exit code 0 if formatted, 1 if not
deno fmt --check src/
--fail-fast
boolean
Stop checking after first unformatted file
deno fmt --check --fail-fast

Watch Mode

--watch
string
Watch for file changes and format automatically
# Watch mode
deno fmt --watch

# Watch specific paths
deno fmt --watch=src/
--no-clear-screen
boolean
Don’t clear the screen on watch mode restart

Formatting Options

--use-tabs
boolean
Use tabs instead of spaces for indentation
deno fmt --use-tabs
--line-width
number
Set the maximum line width (default: 80)
deno fmt --line-width=120
--indent-width
number
Set the number of spaces for indentation (default: 2)
deno fmt --indent-width=4
--single-quote
boolean
Use single quotes instead of double quotes
deno fmt --single-quote
--prose-wrap
string
How to wrap prose in markdown (always, never, preserve)
deno fmt --prose-wrap=always
--no-semicolons
boolean
Don’t use semicolons except where necessary
deno fmt --no-semicolons

File Filtering

--ignore
string
Ignore files or directories
deno fmt --ignore=build/,dist/

Configuration

Formatting options can be configured in deno.json:
{
  "fmt": {
    "useTabs": false,
    "lineWidth": 80,
    "indentWidth": 2,
    "singleQuote": false,
    "proseWrap": "preserve",
    "include": ["src/"],
    "exclude": ["dist/", "build/"]
  }
}

Ignoring Code

Ignore File

Add a comment at the top of the file:
// deno-fmt-ignore-file

const    unformatted   =    "code";

Ignore Next Line

// deno-fmt-ignore
const    unformatted   =    "code";

Ignore Range

// deno-fmt-ignore-start
const    unformatted   =    "code";
let      another       =    "value";
// deno-fmt-ignore-end

Examples

Format Specific Extensions

# Format only TypeScript files
deno fmt **/*.ts

# Format only JSON files
deno fmt **/*.json

CI/CD Integration

# Check formatting in CI
deno fmt --check || exit 1

# Format and show diff
deno fmt --check 2>&1 | tee format-report.txt

Pre-commit Hook

#!/bin/bash
# .git/hooks/pre-commit

if ! deno fmt --check; then
  echo "Please run 'deno fmt' before committing"
  exit 1
fi

Format with Custom Settings

# Format with custom line width and single quotes
deno fmt --line-width=120 --single-quote src/

# Format with tabs
deno fmt --use-tabs --indent-width=4 src/

Build docs developers (and LLMs) love