Code formatter

Deno ships with a built in code formatter that auto-formats TypeScript and JavaScript code.

  1. # format all JS/TS files in the current directory and subdirectories
  2. deno fmt
  3. # format specific files
  4. deno fmt myfile1.ts myfile2.ts
  5. # check if all the JS/TS files in the current directory and subdirectories are formatted
  6. deno fmt --check
  7. # format stdin and write to stdout
  8. cat file.ts | deno fmt -

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

  1. // deno-fmt-ignore
  2. export const identity = [
  3. 1, 0, 0,
  4. 0, 1, 0,
  5. 0, 0, 1,
  6. ];

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