runtime/reference/cli/fmt.md
To see a list of the available CLI options for deno fmt, run:
deno fmt --help
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 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.
:::
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:
deno fmt --check --fail-fast
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.
Ignore formatting next item by preceding it with <!--- deno-fmt-ignore -->
comment:
<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.
Ignore formatting next item by preceding it with # deno-fmt-ignore comment:
# deno-fmt-ignore aaaaaa: bbbbbbb
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.