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. 相關工具及測試

程式碼格式化

Previous腳本安裝NextDeno 命名空間與編譯器 API

Last updated 4 years ago

Was this helpful?

程式碼格式化

該功能是基於 實作出來的,至於什麼是格式化呢?

我們先來看亂七八糟的程式碼:

function sum(){
let a = 10;
	let b =20;
return a+ b;
}

上面是所謂的亂器八糟程式碼,假設筆者今天就是這種程式碼的製造者,想要洗心革面卻又不知道該從何下手,

在 Deno 中,就提供了這樣的工具可以幫你一鍵整理程式碼 (支援 TypeScript 以及 JavaScript ):

# format all JS/TS files in the current directory and subdirectories
deno fmt
# format specific files
deno fmt myfile1.ts myfile2.ts
# check if all the JS/TS files in the current directory and subdirectories are formatted
deno fmt --check
# format stdin and write to stdout
cat file.ts | deno fmt -

忽略格式化

如果使用者不希望有些程式碼被打理的漂漂亮亮(?),可以這麼做:

  1. 在程式碼前面加上 // deno-fmt-ignore :

    // deno-fmt-ignore
    export const identity = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1,
    ];
  2. 直接在程式碼頂部加上 // deno-fmt-ignore-file

dprint