2020-06-12 09:31:04 -04:00
|
|
|
## Linter
|
|
|
|
|
|
|
|
Deno ships with a built in code linter for JavaScript and TypeScript.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
# lint all JS/TS files in the current directory and subdirectories
|
2021-04-27 06:44:36 -04:00
|
|
|
deno lint
|
2020-06-12 09:31:04 -04:00
|
|
|
# lint specific files
|
2021-04-27 06:44:36 -04:00
|
|
|
deno lint myfile1.ts myfile2.ts
|
2020-10-26 08:36:13 -04:00
|
|
|
# print result as JSON
|
2021-04-27 06:44:36 -04:00
|
|
|
deno lint --json
|
2020-10-26 08:36:13 -04:00
|
|
|
# read from stdin
|
2021-04-27 06:44:36 -04:00
|
|
|
cat file.ts | deno lint -
|
2020-06-12 09:31:04 -04:00
|
|
|
```
|
|
|
|
|
2020-08-31 07:53:42 -04:00
|
|
|
For more detail, run `deno lint --help`.
|
|
|
|
|
2020-06-12 09:31:04 -04:00
|
|
|
### Available rules
|
|
|
|
|
2020-08-29 06:58:20 -04:00
|
|
|
- `adjacent-overload-signatures`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `ban-ts-comment`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `ban-types`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `ban-untagged-ignore`
|
2020-12-02 11:06:25 -05:00
|
|
|
- `camelcase`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `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`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-constant-condition`
|
|
|
|
- `no-control-regex`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-debugger`
|
|
|
|
- `no-delete-var`
|
2021-05-15 09:12:33 -04:00
|
|
|
- `no-deprecated-deno-api`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-dupe-args`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-dupe-class-members`
|
|
|
|
- `no-dupe-else-if`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-dupe-keys`
|
|
|
|
- `no-duplicate-case`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-empty`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-empty-character-class`
|
|
|
|
- `no-empty-interface`
|
|
|
|
- `no-empty-pattern`
|
|
|
|
- `no-ex-assign`
|
|
|
|
- `no-explicit-any`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-extra-boolean-cast`
|
|
|
|
- `no-extra-non-null-assertion`
|
|
|
|
- `no-extra-semi`
|
2020-09-13 09:17:25 -04:00
|
|
|
- `no-fallthrough`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-func-assign`
|
2020-09-13 09:17:25 -04:00
|
|
|
- `no-global-assign`
|
|
|
|
- `no-import-assign`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-inferrable-types`
|
2020-09-13 09:17:25 -04:00
|
|
|
- `no-inner-declarations`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-invalid-regexp`
|
|
|
|
- `no-irregular-whitespace`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-misused-new`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-mixed-spaces-and-tabs`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-namespace`
|
|
|
|
- `no-new-symbol`
|
2020-09-09 10:45:31 -04:00
|
|
|
- `no-obj-calls`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-octal`
|
|
|
|
- `no-prototype-builtins`
|
2020-09-13 09:17:25 -04:00
|
|
|
- `no-redeclare`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-regex-spaces`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-self-assign`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-setter-return`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-shadow-restricted-names`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-this-alias`
|
|
|
|
- `no-this-before-super`
|
2020-09-09 10:45:31 -04:00
|
|
|
- `no-unreachable`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-unsafe-finally`
|
|
|
|
- `no-unsafe-negation`
|
2020-08-29 06:58:20 -04:00
|
|
|
- `no-unused-labels`
|
2021-05-15 09:12:33 -04:00
|
|
|
- `no-unused-vars`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `no-with`
|
|
|
|
- `prefer-as-const`
|
2020-12-02 11:06:25 -05:00
|
|
|
- `prefer-const`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `prefer-namespace-keyword`
|
2020-12-02 11:06:25 -05:00
|
|
|
- `require-await`
|
2020-06-12 09:31:04 -04:00
|
|
|
- `require-yield`
|
|
|
|
- `use-isnan`
|
|
|
|
- `valid-typeof`
|
|
|
|
|
2020-12-02 11:06:25 -05:00
|
|
|
For more detail about each rule, visit
|
|
|
|
[the deno_lint rule documentation](https://lint.deno.land).
|
|
|
|
|
2020-06-12 09:31:04 -04:00
|
|
|
### Ignore directives
|
|
|
|
|
|
|
|
#### Files
|
|
|
|
|
|
|
|
To ignore whole file `// deno-lint-ignore-file` directive should placed at the
|
2020-08-17 12:17:57 -04:00
|
|
|
top of the file:
|
2020-06-12 09:31:04 -04:00
|
|
|
|
|
|
|
```ts
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
|
|
|
|
function foo(): any {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-12-10 14:45:45 -05:00
|
|
|
Ignore directive must be placed before first statement or declaration:
|
2020-06-12 09:31:04 -04:00
|
|
|
|
|
|
|
```ts
|
|
|
|
// 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 {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-09-15 04:02:19 -04:00
|
|
|
You can also ignore certain diagnostics in the whole file
|
|
|
|
|
|
|
|
```ts
|
|
|
|
// deno-lint-ignore-file no-explicit-any no-empty
|
|
|
|
|
|
|
|
function foo(): any {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-06-12 09:31:04 -04:00
|
|
|
#### Diagnostics
|
|
|
|
|
|
|
|
To ignore certain diagnostic `// deno-lint-ignore <codes...>` directive should
|
2020-08-17 12:17:57 -04:00
|
|
|
be placed before offending line. Specifying ignored rule name is required:
|
2020-06-12 09:31:04 -04:00
|
|
|
|
|
|
|
```ts
|
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
function foo(): any {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
// deno-lint-ignore no-explicit-any explicit-function-return-type
|
|
|
|
function bar(a: any) {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|