1 { 2 "plugins": [ 3 // "react", 4 "html" 5 ], 6 "env": { 7 "node": true, 8 "jquery": true, 9 "es6": true, 10 "browser": true 11 }, 12 "globals": { 13 "angular": false 14 }, 15 "parser": "babel-eslint", 16 "rules": { 17 //官方文檔 http://eslint.org/docs/rules/ 18 //參數:0 關閉,1 警告,2 錯誤 19 // "quotes": [0, "single"], //建議使用單引號 20 // "no-inner-declarations": [0, "both"], //不建議在{}代碼塊內部聲明變量或函數 21 "no-extra-boolean-cast": 1, //多餘的感嘆號轉布爾型 22 "no-extra-semi": 1, //多餘的分號 23 "no-extra-parens": 0, //多餘的括號 24 "no-empty": 1, //空代碼塊 25 26 //使用前未定義 27 "no-use-before-define": [ 28 0, 29 "nofunc" 30 ], 31 32 "complexity": [0, 10], //圈複雜度大於* 33 34 //定義數組或對象最後多餘的逗號 35 "comma-dangle": [ 36 0, 37 "never" 38 ], 39 40 // 不容許對全局變量賦值,如 window = 'abc' 41 "no-global-assign": ["error", { 42 // 定義例外 43 // "exceptions": ["Object"] 44 }], 45 "no-var": 0, //用let或const替代var 46 "no-const-assign": 2, //不容許const從新賦值 47 "no-class-assign": 2, //不容許對class從新賦值 48 "no-debugger": 1, //debugger 調試代碼未刪除 49 "no-console": 0, //console 未刪除 50 "no-constant-condition": 2, //常量做爲條件 51 "no-dupe-args": 2, //參數重複 52 "no-dupe-keys": 2, //對象屬性重複 53 "no-duplicate-case": 2, //case重複 54 "no-empty-character-class": 2, //正則沒法匹配任何值 55 "no-invalid-regexp": 2, //無效的正則 56 "no-func-assign": 2, //函數被賦值 57 "valid-typeof": 1, //無效的類型判斷 58 "no-unreachable": 2, //不可能執行到的代碼 59 "no-unexpected-multiline": 2, //行尾缺乏分號可能致使一些意外狀況 60 "no-sparse-arrays": 1, //數組中多出逗號 61 "no-shadow-restricted-names": 2, //關鍵詞與命名衝突 62 "no-undef": 1, //變量未定義 63 "no-unused-vars": 1, //變量定義後未使用 64 "no-cond-assign": 2, //條件語句中禁止賦值操做 65 "no-native-reassign": 2, //禁止覆蓋原生對象 66 "no-mixed-spaces-and-tabs": 0, 67 68 69 70 //代碼風格優化 -------------------------------------- 71 "no-irregular-whitespace": 0, 72 "no-else-return": 0, //在else代碼塊中return,else是多餘的 73 "no-multi-spaces": 0, //不容許多個空格 74 75 //object直接量建議寫法 : 後一個空格前面不留空格 76 "key-spacing": [ 77 0, 78 { 79 "beforeColon": false, 80 "afterColon": true 81 } 82 ], 83 84 "block-scoped-var": 1, //變量應在外部上下文中聲明,不該在{}代碼塊中 85 "consistent-return": 1, //函數返回值多是不一樣類型 86 "accessor-pairs": 1, //object getter/setter方法須要成對出現 87 88 //換行調用對象方法 點操做符應寫在行首 89 "dot-location": [ 90 1, 91 "property" 92 ], 93 "no-lone-blocks": 1, //多餘的{}嵌套 94 "no-labels": 1, //無用的標記 95 "no-extend-native": 1, //禁止擴展原生對象 96 "no-floating-decimal": 1, //浮點型須要寫全 禁止.1 或 2.寫法 97 "no-loop-func": 1, //禁止在循環體中定義函數 98 "no-new-func": 1, //禁止new Function(...) 寫法 99 "no-self-compare": 1, //不允與本身比較做爲條件 100 "no-sequences": 1, //禁止可能致使結果不明確的逗號操做符 101 "no-throw-literal": 1, //禁止拋出一個直接量 應是Error對象 102 103 //不允return時有賦值操做 104 "no-return-assign": [ 105 1, 106 "always" 107 ], 108 109 //不容許重複聲明 110 "no-redeclare": [ 111 1, 112 { 113 "builtinGlobals": true 114 } 115 ], 116 117 //不執行的表達式 118 "no-unused-expressions": [ 119 0, 120 { 121 "allowShortCircuit": true, 122 "allowTernary": true 123 } 124 ], 125 "no-useless-call": 1, //無心義的函數call或apply 126 "no-useless-concat": 1, //無心義的string concat 127 "no-void": 1, //禁用void 128 "no-with": 1, //禁用with 129 "space-infix-ops": 0, //操做符先後空格 130 131 //jsdoc 132 "valid-jsdoc": [ 133 0, 134 { 135 "requireParamDescription": true, 136 "requireReturnDescription": true 137 } 138 ], 139 140 //標記未寫註釋 141 "no-warning-comments": [ 142 1, 143 { 144 "terms": [ 145 "todo", 146 "fixme", 147 "any other term" 148 ], 149 "location": "anywhere" 150 } 151 ], 152 "curly": 0 //if、else、while、for代碼塊用{}包圍 153 } 154 }