1. 程式人生 > >vue-cli3.0中typeScript中Tslint配置規則

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 }