ende fmt

Ende 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

Format all supported files in the current directory:

ende fmt

Format specific files or directories:

ende fmt main.ts src/

Watch mode

Automatically re-format files when they change:

ende fmt --watch

Check formatting in CI

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

ende fmt --check

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

ende fmt --check --fail-fast

Formatting stdin

Format code piped through stdin — useful for editor integrations:

cat main.ts | ende fmt -

Configuring the formatter

Customize formatting options in your ende.json:

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

See the Configuration page for all available options.

Inheriting settings from .editorconfig

ende fmt also reads .editorconfig files and uses them to fill in any formatting option you have not set elsewhere. The precedence, from highest to lowest, is:

  1. CLI flags (--indent-width, --use-tabs, and so on)
  2. The fmt block in ende.json
  3. .editorconfig
  4. Built-in defaults

So .editorconfig only supplies values you have not already configured through a flag or ende.json. Properties such as indent_style, indent_size, and max_line_length map onto the corresponding ende fmt options.

Including and excluding files

Specify which files to format in ende.json:

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

You can also exclude files from the command line:

ende fmt --ignore=dist/,build/

Supported file types

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
XML .xml
SVG .svg
Nunjucks .njk
Vento .vto
YAML .yml, .yaml
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

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

The markup formatters (HTML, XML, SVG, and the --unstable-component formats) and the style formatters (CSS, SCSS, and Less) were rebuilt to only adjust whitespace. They never reorder or rewrite tokens, and they pass unknown syntax (vendor extensions, future at-rules, template expressions, even broken markup) through unchanged instead of erroring, so formatting is more robust on real-world files.

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

Command line usage:

fmt

Format source files

Options

--check

Check if the source files are formatted.

--config, -c

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

--ext

Set content type of the supplied file.

--fail-fast

Stop checking files on first format error.

--ignore

Ignore formatting particular source files.

--indent-width

Define indentation width [default: 2]

--line-width

Define maximum line width [default: 80]

--no-clear-screen

Do not clear terminal screen when under watch mode.

--no-config

Disable automatic loading of the configuration file.

--no-editorconfig

Don't read .editorconfig files to infer formatting options [default: false]

--no-semicolons

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

--permit-no-files

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

--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]

--watch

Watch for file changes and restart process automatically. Local files from entry point module graph are watched by default. Additional paths might be watched by passing them as arguments to this flag.

--watch-exclude

Exclude provided files/patterns from watch mode.