deno fmt, code formatting
Command line usage
deno fmt [OPTIONS] [files]...Auto-format various file types.
deno fmt myfile1.ts myfile2.ts
Supported file types are:
JavaScript, TypeScript, Markdown, JSON(C) and Jupyter Notebooks
Supported file types which are behind corresponding unstable flags (see formatting options):
HTML, CSS, SCSS, SASS, LESS, YAML, Svelte, Vue, Astro and Angular
Format stdin and write to stdout:
cat file.ts | deno fmt -
Check if the files are formatted:
deno fmt --check
Ignore formatting code by preceding it with an ignore comment:
// deno-fmt-ignore
Ignore formatting a file by adding an ignore comment at the top of the file:
// deno-fmt-ignore-file
Options
--config
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
Disable automatic loading of the configuration file.
Formatting options
--check
Check if the source files are formatted.
--ext
Set content type of the supplied file.
--ignore
Ignore formatting particular source files.
--indent-width
Define indentation width [default: 2]
--line-width
Define maximum line width [default: 80]
--no-semicolons
Don't use semicolons except where necessary [default: false]
--prose-wrap
Define how prose should be wrapped [default: always]
--single-quote
Use single quotes [default: false]
--unstable-component
Enable formatting Svelte, Vue, Astro and Angular files.
--unstable-sql
Enable formatting SQL files.
--use-tabs
Use tabs instead of spaces for indentation [default: false]
File watching options
--no-clear-screen
Do not clear terminal screen when under watch mode.
--watch
Watch for file changes and restart process automatically. Only local files from entry point module graph are watched.
--watch-exclude
Exclude provided files/patterns from watch mode.
Supported File Types
Deno ships with a built-in code formatter that will auto-format the following files:
| 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. |
deno fmt can format code snippets in Markdown files. Snippets must be enclosed in triple backticks and have a language attribute.
Ignoring Code
JavaScript / TypeScript / JSONC
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
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.
YAML
Ignore formatting next item by preceding it with # deno-fmt-ignore comment:
# deno-fmt-ignore aaaaaa: bbbbbbb
© 2018–2024 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/reference/cli/formatter