程式碼檢查器
程式碼檢查器
如果讀者原本就有使用主流前端框架開發的經驗,對 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-signaturesban-ts-commentban-typesban-untagged-ignoreconstructor-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-namespace-keywordrequire-yieldtriple-slash-referenceuse-isnanvalid-typeof
Last updated
Was this helpful?