diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-06-12 15:31:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-12 15:31:04 +0200 |
commit | c073f552d9ed18acab02080871c2b70b4951156e (patch) | |
tree | a0462714dda4727e54872701b811ab632d6d0100 | |
parent | 81d09ad01c92a9547cdb388044b3b3ce8b077aca (diff) |
docs(lint): add entry in manual (#6258)
-rw-r--r-- | cli/flags.rs | 5 | ||||
-rw-r--r-- | docs/toc.json | 3 | ||||
-rw-r--r-- | docs/tools.md | 2 | ||||
-rw-r--r-- | docs/tools/linter.md | 122 |
4 files changed, 130 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index acfe2f3e9..bd7ea462f 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -919,6 +919,11 @@ rule name: // deno-lint-ignore require-await no-empty +Names of rules to ignore must be specified after ignore comment. + +ESLint ignore comments are also supported: + // eslint-ignore-next-line @typescrit-eslint/no-explicit-any no-empty + Ignore linting a file by adding an ignore comment at the top of the file: // deno-lint-ignore-file ", diff --git a/docs/toc.json b/docs/toc.json index dd9793aa8..86ac7097d 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -46,7 +46,8 @@ "formatter": "Formatter", "bundler": "Bundler", "documentation_generator": "Documentation generator", - "dependency_inspector": "Dependency inspector" + "dependency_inspector": "Dependency inspector", + "linter": "Linter" } }, "embedding_deno": { diff --git a/docs/tools.md b/docs/tools.md index 2754de43b..5307a6a89 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -12,6 +12,6 @@ and TypeScript: - [documentation generator (`deno doc`)](./tools/documentation_generator.md) - [formatter (`deno fmt`)](./tools/formatter.md) - [test runner (`deno test`)](./testing.md) -- linter (`deno lint`) [coming soon](https://github.com/denoland/deno/issues/1880) +- [linter (`deno lint`)](./tools/linter.md) <!-- prettier-ignore-end --> diff --git a/docs/tools/linter.md b/docs/tools/linter.md new file mode 100644 index 000000000..96c9c1b4e --- /dev/null +++ b/docs/tools/linter.md @@ -0,0 +1,122 @@ +## 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** + +```shell +# 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 + +- `ban-ts-comment` +- `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-debugger` +- `no-delete-var` +- `no-dupe-args` +- `no-dupe-keys` +- `no-duplicate-case` +- `no-empty-character-class` +- `no-empty-interface` +- `no-empty-pattern` +- `no-empty` +- `no-ex-assign` +- `no-explicit-any` +- `no-func-assign` +- `no-misused-new` +- `no-namespace` +- `no-new-symbol` +- `no-obj-call` +- `no-octal` +- `no-prototype-builtins` +- `no-regex-spaces` +- `no-setter-return` +- `no-this-alias` +- `no-this-before-super` +- `no-unsafe-finally` +- `no-unsafe-negation` +- `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. + +```ts +// deno-lint-ignore-file + +function foo(): any { + // ... +} +``` + +Ignore directive must be placed before first stament or declaration: + +```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 { + // ... +} +``` + +#### Diagnostics + +To ignore certain diagnostic `// deno-lint-ignore <codes...>` directive should +be placed before offending line. Specifying ignored rule name is required. + +```ts +// 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 in `// deno-lint-ignore` it's +required to specify ignored rule name is required. + +```ts +// eslint-ignore-next-line no-empty +while (true) {} + +// eslint-ignore-next-line @typescript-eslint/no-explicit-any +function bar(a: any) { + // ... +} +``` |