vue-cli3.0中typeScript中Tslint配置規則


配置之后必須npm run serve重啟一下,不然設置不會生效

{
 // 禁止自動檢測末尾行必須使用逗號,always總是檢測,never從不檢測,ignore忽略檢測
   "trailing-comma": [true, {
    "singleline": "never",
    "multiline": {
      "objects": "ignore",
      "arrays": "always",
      "functions": "never",
      "typeLiterals": "ignore"
    }
  }],
 // 禁止給類的構造函數的參數添加修飾符 "no-parameter-properties": false, // 禁止使用 debugger "no-debugger": false, // 禁止行尾有空格 "no-trailing-whitespace": false, // 禁止無用的表達式 "no-unused-expression": true, // 定義過的變量必須使用 "no-unused-variable": true, // 變量必須先定義后使用 "no-use-before-declare": true, // 禁止使用 var "no-var-keyword": true, // 必須使用 === 或 !==,禁止使用 == 或 !=,與 null 比較時除外 "triple-equals": true, // 指定類成員的排序規則 "member-ordering": false, // 禁止將 this 賦值給其他變量,除非是解構賦值 "no-this-assignment": [ false, { "allowed-names": [ "^self$", "^that$" ], "allow-destructuring": true } ], // 必須使用箭頭函數,除非是單獨的函數聲明或是命名函數 "only-arrow-functions": [ true, "allow-declarations", "allow-named-functions" ], // 禁止出現空代碼塊,允許 catch 是空代碼塊 "no-empty": [ true, "allow-empty-catch" ], // 禁止無用的類型斷言 "no-unnecessary-type-assertion": true, // 使用 return; 而不是 return undefined; "return-undefined": true, // 禁止對 array 使用 for in 循環 "no-for-in-array": true, "comment-format": [ true, "check-space" ], // 單行注釋格式化規則 // 定義函數時如果用到了覆寫,則必須將覆寫的函數寫到一起 "adjacent-overload-signatures": true, // 禁止對函數的參數重新賦值 "no-parameter-reassignment": true, // if 后面必須有 {,除非是單行 if "curly": [ true, "ignore-same-line" ], // for in 內部必須有 hasOwnProperty "forin": true, // 禁止在分支條件判斷中有賦值操作 "no-conditional-assignment": true, // 禁止使用 new 來生成 String, Number 或 Boolean "no-construct": true, // 禁止 super 在一個構造函數中出現兩次 "no-duplicate-super": true, // 禁止在 switch 語句中出現重復測試表達式的 case "no-duplicate-switch-case": true, // 禁止出現重復的變量定義或函數參數名 "no-duplicate-variable": [ true, "check-parameters" ], // 禁止使用 eval "no-eval": true, // 禁止對對象字面量進行類型斷言(斷言成 any 是允許的) "no-object-literal-type-assertion": true, // 禁止沒必要的 return await "no-return-await": true, // 禁止在數組中出現連續的逗號,如 let foo = [,,] "no-sparse-arrays": true, // 禁止 throw 字符串,必須 throw 一個 Error 對象 "no-string-throw": true, // switch 的 case 必須 return 或 break "no-switch-case-fall-through": true, // 使用實例的方法時,必須 bind 到實例上 "no-unbound-method": [ true, "ignore-static" ], // 使用 { ...foo, bar: 1 } 代替 Object.assign({}, foo, { bar: 1 }) // 前者的類型檢查更完善 "prefer-object-spread": true, // parseInt 必須傳入第二個參數 "radix": true, // 必須使用 isNaN(foo) 而不是 foo === NaN "use-isnan": true, // // // 可維護性 // 這些規則可以增加代碼的可維護性 // // 禁止函數的循環復雜度超過 20,https://en.wikipedia.org/wiki/Cyclomatic_complexity "cyclomatic-complexity": [ true, 20 ], // 禁止使用廢棄(被標識了 @deprecated)的 API "deprecation": true, // 一個縮進必須用四個空格替代 "indent": [ true, "spaces", 4 ], // 禁止出現重復的 import "no-duplicate-imports": true, // 禁止一個文件中出現多個相同的 namespace "no-mergeable-namespace": true, // 文件類型必須時 utf-8 "encoding": true, // import 語句中,關鍵字之間的間距必須是一個空格 "import-spacing": true, // 接口可以 implement extend 和 merge "interface-over-type-literal": true, // new 后面只必須有一個空格 "new-parens": true, // 類型斷言必須使用 as Type,禁止使用 <Type> // <Type> 容易被理解為 jsx "no-angle-bracket-type-assertion": true, // 禁止連續超過三行空行 "no-consecutive-blank-lines": [ true, 3 ], // 禁止使用特殊空白符(比如全角空格) "no-irregular-whitespace": true, // 禁止使用 JSDoc,因為 TypeScirpt 已經包含了大部分功能 "no-redundant-jsdoc": true, // 禁止使用三斜杠引入類型定義文件 "no-reference-import": true, // 禁止變量定義時賦值為 undefined "no-unnecessary-initializer": true, // 小數必須以 0. 開頭,禁止以 . 開頭,並且不能以 0 結尾 "number-literal-format": true, // 必須使用 a = {b} 而不是 a = {b: b} "object-literal-shorthand": true, // 變量申明必須每行一個,for 循環的初始條件中除外 "one-variable-per-declaration": [ true, "ignore-for-loop" ], // if 后的 { 禁止換行 "one-line": true, // 必須使用單引號,jsx 中必須使用雙引號 "quotemark": [ true, "single", "jsx-double", "avoid-template", "avoid-escape" ], // 行尾必須有分號 "semicolon": [ true, "always", "ignore-interfaces" ], // 函數名前必須有空格 "space-before-function-paren": [ true, "asyncArrow" ], // 括號內首尾禁止有空格 "space-within-parens": [ true, 0 ], // 禁止 finally 內出現 return, continue, break, throw 等 // finally 會比 catch 先執行 "no-unsafe-finally": true } 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM