> For the complete documentation index, see [llms.txt](https://ianchen0119.gitbook.io/deno/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ianchen0119.gitbook.io/deno/deno-cli/xiang-guan-gong-ju-ji-ce-shi/cheng-shi-ma-jian-cha-qi.md).

# 程式碼檢查器

### 程式碼檢查器

如果讀者原本就有使用主流前端框架開發的經驗，對 ESLint 肯定不陌生（嗎？）。

Deno 內建了程式碼檢查器，可以用於檢查使用者的 TypeScript 和 JavaScript 程式碼是否符合規範。

```
# 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 -
# get more details
deno lint --help
```

> 注意： 該功能還不是很穩定，所以在使用時一樣要加上 `--unstable` 唷！

#### 忽略指令

我們可以使用忽略指令來跳過不想被檢查的檔案：

```
// deno-lint-ignore-file

function foo(): any {
  // ...
}
```

`// deno-lint-ignore-file` 可以選擇放在文件的最頂端或是第一次宣告的前方。

此外，我們也可以讓忽略指令用來跳過特定的規則的檢查：

```
// deno-lint-ignore no-explicit-any
function foo(): any {
  // ...
}

// deno-lint-ignore no-explicit-any explicit-function-return-type
function bar(a: any) {
  // ...
}
```

最後， Deno 還特別兼容了 ESLint 的指令：

```
// eslint-disable-next-line no-empty
while (true) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function bar(a: any) {
  // ...
}
```

> 需要注意的是：與 `// deno-lint-ignore` 一樣，使用時需要指定被忽略的規則名稱唷！

至於詳細的規則有：

* &#x20;`adjacent-overload-signatures`
* &#x20;`ban-ts-comment`
* &#x20;`ban-types`
* &#x20;`ban-untagged-ignore`
* &#x20;`constructor-super`
* &#x20;`for-direction`
* &#x20;`getter-return`
* &#x20;`no-array-constructor`
* &#x20;`no-async-promise-executor`
* &#x20;`no-case-declarations`
* &#x20;`no-class-assign`
* &#x20;`no-compare-neg-zero`
* &#x20;`no-cond-assign`
* &#x20;`no-constant-condition`
* &#x20;`no-control-regex`
* &#x20;`no-debugger`
* &#x20;`no-delete-var`
* &#x20;`no-dupe-args`
* &#x20;`no-dupe-class-members`
* &#x20;`no-dupe-else-if`
* &#x20;`no-dupe-keys`
* &#x20;`no-duplicate-case`
* &#x20;`no-empty`
* &#x20;`no-empty-character-class`
* &#x20;`no-empty-interface`
* &#x20;`no-empty-pattern`
* &#x20;`no-ex-assign`
* &#x20;`no-explicit-any`
* &#x20;`no-extra-boolean-cast`
* &#x20;`no-extra-non-null-assertion`
* &#x20;`no-extra-semi`
* &#x20;`no-fallthrough`
* &#x20;`no-func-assign`
* &#x20;`no-global-assign`
* &#x20;`no-import-assign`
* &#x20;`no-inferrable-types`
* &#x20;`no-inner-declarations`
* &#x20;`no-invalid-regexp`
* &#x20;`no-irregular-whitespace`
* &#x20;`no-misused-new`
* &#x20;`no-mixed-spaces-and-tabs`
* &#x20;`no-namespace`
* &#x20;`no-new-symbol`
* &#x20;`no-obj-calls`
* &#x20;`no-octal`
* &#x20;`no-prototype-builtins`
* &#x20;`no-redeclare`
* &#x20;`no-regex-spaces`
* &#x20;`no-self-assign`
* &#x20;`no-setter-return`
* &#x20;`no-shadow-restricted-names`
* &#x20;`no-this-alias`
* &#x20;`no-this-before-super`
* &#x20;`no-undef`
* &#x20;`no-unreachable`
* &#x20;`no-unsafe-finally`
* &#x20;`no-unsafe-negation`
* &#x20;`no-unused-labels`
* &#x20;`no-with`
* &#x20;`prefer-as-const`
* &#x20;`prefer-namespace-keyword`
* &#x20;`require-yield`
* &#x20;`triple-slash-reference`
* &#x20;`use-isnan`
* &#x20;`valid-typeof`
