#deno #lint #box

deno_lint

lint for deno

31 releases

new 0.2.4 Oct 17, 2020
0.2.3 Oct 7, 2020
0.2.0 Sep 13, 2020
0.1.29 Sep 9, 2020
0.1.12 Jun 30, 2020

#39 in Hardware support

Download history 1176/week @ 2020-06-28 1471/week @ 2020-07-05 877/week @ 2020-07-12 846/week @ 2020-07-19 982/week @ 2020-07-26 936/week @ 2020-08-02 1325/week @ 2020-08-09 1589/week @ 2020-08-16 1661/week @ 2020-08-23 1761/week @ 2020-08-30 916/week @ 2020-09-06 687/week @ 2020-09-13 468/week @ 2020-09-20 869/week @ 2020-09-27 1272/week @ 2020-10-04 996/week @ 2020-10-11

4,733 downloads per month
Used in 2 crates

MIT license

1MB
26K SLoC

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.

Supports recommended set of rules from ESLint and @typescript-eslint out of the box with no config.

See the roadmap


Performance

Blazing fast, see comparison with ESLint:

[
  {
    "name": "deno_lint",
    "totalMs": 247.20262200000025,
    "runsCount": 5,
    "measuredRunsAvgMs": 49.44052440000005,
    "measuredRunsMs": [
      49.016501999999946,
      49.56810500000006,
      49.68610600000011,
      48.97360200000003,
      49.958307000000104
    ]
  },
  {
    "name": "eslint",
    "totalMs": 12214.295835,
    "runsCount": 5,
    "measuredRunsAvgMs": 2442.859167,
    "measuredRunsMs": [
      2703.5126729999997,
      2380.431925,
      2369.1452910000007,
      2362.1451909999996,
      2399.0607550000004
    ]
  }
]

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

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 {
  // ...
}

You can also ignore certain diagnostics in the whole file

// deno-lint-ignore-file no-explicit-any no-empty

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.47.0).

// check version
$ rustc --version
rustc 1.47.0 (18bf6b4f0 2020-10-07)

// build all targets
$ cargo build --all-targets

// test it
$ cargo test

Generating flamegraph (Linux)

Prerequisites:

$ RUSTFLAGS='-g' cargo build --release --all-targets # build target
$ sudo perf record --call-graph dwarf ./target/release/examples/dlint benchmarks/oak/**.ts # create performance profile
$ perf script | stackcollapse-perf | rust-unmangle | flamegraph > flame.svg # generate flamegraph

These commands can take a few minutes to run.

Contributing

Submitting a Pull Request

Before submitting, please make sure the following is done:

  1. That there is a related issue and it is referenced in the PR text.
  2. There are tests that cover the changes.
  3. Ensure cargo test passes.
  4. Format your code with deno run --allow-run tools/format.ts
  5. Make sure deno run --allow-run tools/lint.ts passes.

Dependencies

~8.5MB
~205K SLoC