Skip to main content
On this page

deno fmt

Deno ships with a built-in code formatter based on dprint that auto-formats your code to a consistent style. For a broader overview, see Linting and Formatting.

Basic usage Jump to heading

Format all supported files in the current directory:

>_
deno fmt

Format specific files or directories:

>_
deno fmt main.ts src/

Watch mode Jump to heading

Automatically re-format files when they change:

>_
deno fmt --watch

Check formatting in CI Jump to heading

Use --check to verify files are formatted without modifying them. The command exits with a non-zero status code if any files are unformatted:

>_
deno fmt --check

Add --fail-fast to stop on the first unformatted file instead of reporting all of them, which is useful in large codebases:

>_
deno fmt --check --fail-fast

Formatting stdin Jump to heading

Format code piped through stdin — useful for editor integrations:

>_
cat main.ts | deno fmt -

Configuring the formatter Jump to heading

Customize formatting options in your deno.json:

deno.json
{
  "fmt": {
    "useTabs": false,
    "lineWidth": 80,
    "indentWidth": 2,
    "semiColons": true,
    "singleQuote": false,
    "proseWrap": "preserve"
  }
}

See the Configuration page for all available options.

Including and excluding files Jump to heading

Specify which files to format in deno.json:

deno.json
{
  "fmt": {
    "include": ["src/"],
    "exclude": ["src/testdata/", "src/generated/**/*.ts"]
  }
}

You can also exclude files from the command line:

>_
deno fmt --ignore=dist/,build/

Supported file types Jump to heading

File Type Extension Notes
JavaScript .js, .cjs, .mjs
TypeScript .ts, .mts, .cts
JSX .jsx
TSX .tsx
Markdown .md, .mkd, .mkdn, .mdwn, .mdown, .markdown
JSON .json
JSONC .jsonc
CSS .css
HTML .html
Nunjucks .njk
Vento .vto
YAML .yml, .yaml
Sass .sass
SCSS .scss
LESS .less
Jupyter Notebook .ipynb
Astro .astro Requires --unstable-component flag or "unstable": ["fmt-component"] config option.
Svelte .svelte Requires --unstable-component flag or "unstable": ["fmt-component"] config option.
Vue .vue Requires --unstable-component flag or "unstable": ["fmt-component"] config option.
SQL .sql Requires --unstable-sql flag or "unstable": ["fmt-sql"] config option.

Note

deno fmt can format code snippets in Markdown files. Snippets must be enclosed in triple backticks and have a language attribute.

Ignoring code Jump to heading

JavaScript / TypeScript / JSONC Jump to heading

Ignore formatting code by preceding it with a // deno-fmt-ignore comment:

// deno-fmt-ignore
export const identity = [
    1, 0, 0,
    0, 1, 0,
    0, 0, 1,
];

Or ignore an entire file by adding a // deno-fmt-ignore-file comment at the top of the file.

Markdown / HTML / CSS Jump to heading

Ignore formatting next item by preceding it with <!--- deno-fmt-ignore --> comment:

HTML
<html>
  <body>
    <p>
      Hello there
      <!-- deno-fmt-ignore -->
    </p>
  </body>
</html>

To ignore a section of code, surround the code with <!-- deno-fmt-ignore-start --> and <!-- deno-fmt-ignore-end --> comments.

Or ignore an entire file by adding a <!-- deno-fmt-ignore-file --> comment at the top of the file.

YAML Jump to heading

Ignore formatting next item by preceding it with # deno-fmt-ignore comment:

HTML
# deno-fmt-ignore aaaaaa: bbbbbbb

Options Jump to heading

--config Jump to heading

Short flag: -c

Configure different aspects of deno including TypeScript, linting, and code formatting. Typically the configuration file will be called deno.json or deno.jsonc and automatically detected; in that case this flag is not necessary.

--no-config Jump to heading

Disable automatic loading of the configuration file.

--permit-no-files Jump to heading

Don't return an error code if no files were found.

Formatting options Jump to heading

--check Jump to heading

Check if the source files are formatted.

--ext Jump to heading

Set content type of the supplied file.

--fail-fast Jump to heading

Stop checking files on first format error.

--ignore Jump to heading

Ignore formatting particular source files.

--indent-width Jump to heading

Define indentation width [default: 2]

--line-width Jump to heading

Define maximum line width [default: 80]

--no-semicolons Jump to heading

Don't use semicolons except where necessary [default: false]

--prose-wrap Jump to heading

Define how prose should be wrapped [default: always]

--single-quote Jump to heading

Use single quotes [default: false]

--unstable-component Jump to heading

Enable formatting Svelte, Vue, Astro and Angular files.

--unstable-sql Jump to heading

Enable formatting SQL files.

--use-tabs Jump to heading

Use tabs instead of spaces for indentation [default: false]

File watching options Jump to heading

--no-clear-screen Jump to heading

Do not clear terminal screen when under watch mode.

--watch Jump to heading

Watch for file changes and restart process automatically. Only local files from entry point module graph are watched.

--watch-exclude Jump to heading

Exclude provided files/patterns from watch mode.

Did you find what you needed?

Privacy policy