mirror of
https://github.com/denoland/deno.git
synced 2025-12-23 08:48:24 +00:00
2.9 KiB
2.9 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
# print result as JSON
deno lint --unstable --json
# read from stdin
cat file.ts | deno lint --unstable -
For more detail, run deno lint --help.
Available rules
adjacent-overload-signaturesban-ts-commentban-typesban-untagged-ignorecamelcaseconstructor-superfor-directiongetter-returnno-array-constructorno-async-promise-executorno-case-declarationsno-class-assignno-compare-neg-zerono-cond-assignno-constant-conditionno-control-regexno-debuggerno-delete-varno-dupe-argsno-dupe-class-membersno-dupe-else-ifno-dupe-keysno-duplicate-caseno-emptyno-empty-character-classno-empty-interfaceno-empty-patternno-ex-assignno-explicit-anyno-extra-boolean-castno-extra-non-null-assertionno-extra-semino-fallthroughno-func-assignno-global-assignno-import-assignno-inferrable-typesno-inner-declarationsno-invalid-regexpno-irregular-whitespaceno-misused-newno-mixed-spaces-and-tabsno-namespaceno-new-symbolno-obj-callsno-octalno-prototype-builtinsno-redeclareno-regex-spacesno-self-assignno-setter-returnno-shadow-restricted-namesno-this-aliasno-this-before-superno-undefno-unreachableno-unsafe-finallyno-unsafe-negationno-unused-labelsno-withprefer-as-constprefer-constprefer-namespace-keywordrequire-awaitrequire-yielduse-isnanvalid-typeof
For more detail about each rule, visit the deno_lint rule documentation.
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 statement 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. 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) {
// ...
}