Deno 入門指南
  • 前言
  • Deno 更新日誌
  • 簡介
    • Deno 跟 Node.js 的主要差異
    • Hello, World!
  • TypeScript 基礎篇
    • 變數宣告
    • 使用型別系統
    • 流程判斷與迴圈
    • 函式宣告
    • This 與 Arrow Function
    • 在函式中應用強型別
    • 介面
    • 型別別名
    • 物件導向概念
    • 類別的封裝與繼承
    • 介面與類別、抽象類別
    • 泛型的概念與實作
    • 型別補充
  • Deno CLI
    • 快速開始
    • 沙盒機制
    • URL Import
    • 編譯選項
    • 相關工具及測試
      • WebGPU API
      • Deno.resolveDns
      • 程式碼編譯器
      • 程式碼檢查器
      • 依賴檢查器
      • 文件產生器
      • 程式碼打包工具
      • 腳本安裝
      • 程式碼格式化
      • Deno 命名空間與編譯器 API
      • 使用 Deno 進行測試
  • 使用 Deno 打造多線程應用
    • 多線程概念
    • Deno Workers
    • 使用多線程計算矩陣相乘
  • 使用 Deno 打造 Web API
    • Web API 介紹
    • Oak 框架介紹
    • 使用 Denon 精簡指令
    • 實作 Web API
    • MongoDB 安裝教學
    • Deno 與 MongoDB 共舞
    • 完成第一支 Web API
    • 淺談跨來源資源共用(CORS)與解決辦法
Powered by GitBook
On this page

Was this helpful?

  1. Deno CLI
  2. 相關工具及測試

程式碼檢查器

程式碼檢查器

如果讀者原本就有使用主流前端框架開發的經驗,對 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 一樣,使用時需要指定被忽略的規則名稱唷!

至於詳細的規則有:

  • adjacent-overload-signatures

  • ban-ts-comment

  • ban-types

  • 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-constant-condition

  • no-control-regex

  • no-debugger

  • no-delete-var

  • no-dupe-args

  • no-dupe-class-members

  • no-dupe-else-if

  • no-dupe-keys

  • no-duplicate-case

  • no-empty

  • no-empty-character-class

  • no-empty-interface

  • no-empty-pattern

  • no-ex-assign

  • no-explicit-any

  • no-extra-boolean-cast

  • no-extra-non-null-assertion

  • no-extra-semi

  • no-fallthrough

  • no-func-assign

  • no-global-assign

  • no-import-assign

  • no-inferrable-types

  • no-inner-declarations

  • no-invalid-regexp

  • no-irregular-whitespace

  • no-misused-new

  • no-mixed-spaces-and-tabs

  • no-namespace

  • no-new-symbol

  • no-obj-calls

  • no-octal

  • no-prototype-builtins

  • no-redeclare

  • no-regex-spaces

  • no-self-assign

  • no-setter-return

  • no-shadow-restricted-names

  • no-this-alias

  • no-this-before-super

  • no-undef

  • no-unreachable

  • no-unsafe-finally

  • no-unsafe-negation

  • no-unused-labels

  • no-with

  • prefer-as-const

  • prefer-namespace-keyword

  • require-yield

  • triple-slash-reference

  • use-isnan

  • valid-typeof

Previous程式碼編譯器Next依賴檢查器

Last updated 4 years ago

Was this helpful?