1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/docs/tools/linter.md
2020-08-29 12:58:20 +02:00

2.7 KiB

Linter

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

Note: linter is a new feature and still unstable thus it requires --unstable flag

# lint all JS/TS files in the current directory and subdirectories
deno lint --unstable
# lint specific files
deno lint --unstable myfile1.ts myfile2.ts

Available rules

  • adjacent-overload-signatures
  • ban-ts-comment
  • ban-types
  • ban-untagged-ignore
  • constructor-super
  • for-direction
  • getter-return
  • no-array-constructor
  • no-async-promise-executor
  • no-case-declarations
  • no-class-assign
  • no-compare-neg-zero
  • no-cond-assign
  • no-constant-condition
  • no-control-regex
  • no-debugger
  • no-delete-var
  • no-dupe-args
  • no-dupe-class-members
  • no-dupe-else-if
  • no-dupe-keys
  • no-duplicate-case
  • no-empty
  • no-empty-character-class
  • no-empty-interface
  • no-empty-pattern
  • no-ex-assign
  • no-explicit-any
  • no-extra-boolean-cast
  • no-extra-non-null-assertion
  • no-extra-semi
  • no-func-assign
  • no-inferrable-types
  • no-invalid-regexp
  • no-irregular-whitespace
  • no-misused-new
  • no-mixed-spaces-and-tabs
  • no-namespace
  • no-new-symbol
  • no-obj-call
  • no-octal
  • no-prototype-builtins
  • no-regex-spaces
  • no-self-assign
  • no-setter-return
  • no-shadow-restricted-names
  • no-this-alias
  • no-this-before-super
  • no-unexpected-multiline
  • no-unsafe-finally
  • no-unsafe-negation
  • no-unused-labels
  • no-with
  • prefer-as-const
  • prefer-namespace-keyword
  • require-yield
  • triple-slash-reference
  • use-isnan
  • valid-typeof

Ignore directives

Files

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

// deno-lint-ignore-file

function foo(): any {
  // ...
}

Ignore directive must be placed before first stament or declaration:

// Copyright 2020 the Deno authors. All rights reserved. MIT license.

/**
 * Some JS doc
 **/

// deno-lint-ignore-file

import { bar } from "./bar.js";

function foo(): any {
  // ...
}

Diagnostics

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

// deno-lint-ignore no-explicit-any
function foo(): any {
  // ...
}

// deno-lint-ignore no-explicit-any explicit-function-return-type
function bar(a: any) {
  // ...
}

To provide some compatibility with ESLint deno lint also supports // eslint-ignore-next-line directive. Just like with // deno-lint-ignore, it's required to specify the ignored rule name:

// eslint-ignore-next-line no-empty
while (true) {}

// eslint-ignore-next-line @typescript-eslint/no-explicit-any
function bar(a: any) {
  // ...
}