Back to Denoland

deno fmt

runtime/reference/cli/fmt.md

latest5.6 KB
Original Source

To see a list of the available CLI options for deno fmt, run:

sh
deno fmt --help

Supported File Types

Deno ships with a built-in code formatter that will auto-format the following files:

<!-- This list needs to be updated along with https://github.com/denoland/deno/blob/main/cli/tools/fmt.rs -->
File TypeExtensionNotes
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.astroRequires --unstable-component flag or "unstable": ["fmt-component"] config option.
Svelte.svelteRequires --unstable-component flag or "unstable": ["fmt-component"] config option.
Vue.vueRequires --unstable-component flag or "unstable": ["fmt-component"] config option.
SQL.sqlRequires --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.

:::

Checking formatting in CI

Use --check to verify files are formatted without modifying them. Add --fail-fast to stop on the first unformatted file instead of reporting all of them, which is useful in large codebases:

sh
deno fmt --check --fail-fast

Ignoring Code

JavaScript / TypeScript / JSONC

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

ts
// 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

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

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

html
# deno-fmt-ignore aaaaaa: bbbbbbb

More about linting and formatting

For more information about linting and formatting in Deno, and the differences between these two utilities, visit the Linting and Formatting page in our Fundamentals section.