deno_lint
A Rust crate for writing fast JavaScript and TypeScript linters.
This crate powers deno lint, but is not Deno specific
and can be used to write linters for Node as well.
NOTE Work-in-progress
Current focus is on getting recommended set of rules from ESLint and @typescript-eslint
working out of the box.
See the roadmap
Performance
Blazing fast, see comparison with ESLint:
[
{
"name": "deno_lint",
"totalMs": 830.5838349999995,
"runsCount": 5,
"runsAvgMs": 166.1167669999999,
"runsMs": [
163.71872200000007,
160.46893499999987,
169.2397719999999,
167.75393099999974,
169.40247499999987
]
},
{
"name": "eslint",
"totalMs": 11783.570954999997,
"runsCount": 5,
"runsAvgMs": 2356.7141909999996,
"runsMs": [
2559.053129,
2383.412156999999,
2261.1746249999997,
2306.645263999999,
2273.28578
]
}
]
Benchmarks are run during CI on Ubuntu, using the same set of rules for both linters.
Test subject is oak server consisting of about 50 files.
See ./benchmarks/ directory for more info.
Supported rules
ban-ts-commentban-ts-ignoreban-typesban-untagged-ignoreban-untagged-todoconstructor-superdefault-param-lasteqeqeqexplicit-function-return-typefor-directiongetter-returnno-array-constructorno-async-promise-executorno-await-in-loopno-case-declarationsno-class-assignno-compare-neg-zerono-cond-assignno-const-assignno-debuggerno-delete-varno-dupe-argsno-dupe-class-membersno-dupe-else-ifno-dupe-keysno-duplicate-caseno-empty-character-classno-empty-interfaceno-empty-patternno-emptyno-evalno-ex-assignno-explicit-anyno-extra-boolean-castno-extra-non-null-assertionno-extra-semino-func-assignno-inferrable-typesno-misused-newno-namespaceno-new-symbolno-non-null-assertionno-obj-callsno-octalno-prototype-builtinsno-regex-spacesno-setter-returnno-shadow-restricted-namesno-sparse-arrayno-this-aliasno-this-before-superno-throw-literalno-unsafe-finallyno-unsafe-negationno-unused-labelsno-varno-withprefer-as-constprefer-namespace-keywordrequire-yieldsingle-var-declaratortriple-slash-referenceuse-isnanvalid-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.
// deno-lint-ignore no-explicit-any
function foo(): any {
// ...
}
// deno-lint-ignore no-explicit-any explicit-function-return-type
function bar(a: any) {
// ...
}
Specyfing rule code that will be ignored is required.
Example
examples/dlint/main.rs provides a minimal standalone binary demonstrating
how deno_lint can be used as a crate.
$ ▶ target/debug/examples/dlint ../deno/std/http/server.ts ../deno/std/http/file_server.ts
(no-empty) Empty block statement
--> ../deno/std/http/server.ts:93:14
|
93 | } catch {}
| ^^
|
(no-empty) Empty block statement
--> ../deno/std/http/server.ts:111:44
|
111 | while ((await body.read(buf)) !== null) {}
| ^^
|
(no-empty) Empty block statement
--> ../deno/std/http/server.ts:120:41
|
120 | constructor(public listener: Listener) {}
| ^^
|
(ban-untagged-todo) TODO should be tagged with (@username) or (#issue)
--> ../deno/std/http/file_server.ts:5:0
|
5 | // TODO Stream responses instead of reading them into memory.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
(ban-untagged-todo) TODO should be tagged with (@username) or (#issue)
--> ../deno/std/http/file_server.ts:6:0
|
6 | // TODO Add tests like these:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
(ban-untagged-todo) TODO should be tagged with (@username) or (#issue)
--> ../deno/std/http/file_server.ts:137:0
|
137 | // TODO: simplify this after deno.stat and deno.readDir are fixed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
(no-empty) Empty block statement
--> ../deno/std/http/file_server.ts:155:16
|
155 | } catch (e) {}
| ^^
|
Found 7 problems
For more concrete implementation visit deno
Developing
Make sure to have latest stable version of Rust installed (1.44.0).
// check version
$ rustc --version
rustc 1.44.0 (49cae5576 2020-06-01)
// build all targets
$ cargo build --all-targets
// test it
$ cargo test
Contributing
-
If you are going to work on an issue, mention so in the issue comments before you start working on the issue.
-
Please be professional in the forums. We follow Rust's code of conduct (CoC) Have a problem? Email ry@tinyclouds.org.
-
Ask for help in the community chat room.
Submitting a Pull Request
Before submitting, please make sure the following is done:
- That there is a related issue and it is referenced in the PR text.
- There are tests that cover the changes.
- Ensure
cargo testpasses. - Format your code with
deno run --allow-run tools/format.ts - Make sure
deno run --allow-run tools/lint.tspasses.