Linter

Deno ships with a built-in code linter for JavaScript and TypeScript.

  1. # lint all JS/TS files in the current directory and subdirectories
  2. deno lint
  3. # lint specific files
  4. deno lint myfile1.ts myfile2.ts
  5. # lint all JS/TS files in specified directory and subdirectories
  6. deno lint src/
  7. # print result as JSON
  8. deno lint --json
  9. # read from stdin
  10. cat file.ts | deno lint -

For more detail, run deno lint --help.

Available rules

For a complete list of supported rules visit the deno_lint rule documentation.

Ignore directives

Files

To ignore whole file // deno-lint-ignore-file directive should placed at the top of the file:

  1. // deno-lint-ignore-file
  2. function foo(): any {
  3. // ...
  4. }

Ignore directive must be placed before first statement or declaration:

  1. // Copyright 2020 the Deno authors. All rights reserved. MIT license.
  2. /**
  3. * Some JS doc
  4. */
  5. // deno-lint-ignore-file
  6. import { bar } from "./bar.js";
  7. function foo(): any {
  8. // ...
  9. }

You can also ignore certain diagnostics in the whole file

  1. // deno-lint-ignore-file no-explicit-any no-empty
  2. function foo(): any {
  3. // ...
  4. }

Diagnostics

To ignore certain diagnostic // deno-lint-ignore <codes...> directive should be placed before offending line. Specifying ignored rule name is required:

  1. // deno-lint-ignore no-explicit-any
  2. function foo(): any {
  3. // ...
  4. }
  5. // deno-lint-ignore no-explicit-any explicit-function-return-type
  6. function bar(a: any) {
  7. // ...
  8. }

Configuration

Starting with Deno v1.14 a linter can be customized using either a configuration file or following CLI flags:

  • --rules-tags - List of tag names that will be run. Empty list disables all tags and will only use rules from include. Defaults to “recommended”.

  • --rules-exclude - List of rule names that will be excluded from configured tag sets. If the same rule is in include it will be run.

  • --rules-include - List of rule names that will be run. Even if the same rule is in exclude it will be run.