徹底離線安裝VSCode插件--Eslint

   最近折騰了一番,總算把Eslint插件在離線的狀況下安裝好了。以前查了挺多,可是不少方法仍是在沒有徹底離線的狀況下進行的。之因此想徹底離線安裝,主要是由於咱們工做的地方是禁止訪問外網的,因此像直接執行npm命令來進行一些包的安裝,其實對我來講是用不了的。
  好了,如今進入正題,說下個人解決方式吧。
 
  1.在沒法聯網的電腦上先把VSCode安裝好。
  2.在家裏有網的電腦上,在vsCode裏面的擴展直接安裝eslint插件,而後在該路徑(C:\Users\Administrator\.vscode\extensions)下,
  把eslint插件 的文件夾 (dbaeumer.vscode-eslint-1.2.11)直接拷貝出來,放到沒法聯網的電腦對應的目錄。
  3.有網的和沒法連網電腦上都安裝nodeJs。安裝這個的目的是能夠使用接下來要使用到的nmp庫以及nmp命令(沒法連網的不用使用到這個命令)。
  4.在有網的電腦上的命令行界面執行如下的命令:
      npm i eslint -g
      npm eslint init
      npm install eslint-plugin-html -g
      npm install babel-eslint -g
  這些命令執行的結果都是把這些對應的包下載到本地的nmp庫中,以供後面啓動Eslint插件的時候使用。(-g是全局安裝的意思)
  那咱們如今就是須要把這些安裝好的包找到,把該目錄(C:\Users\Administrator\AppData\Roaming\npm)下的全部文件拷貝到沒法聯網的電腦對應的目錄上就好了。
  5.最後,重要的文件:.eslintrc.json(最前面有個點的,看清楚啦!我就被這個坑過。),要把它放到要使用eslint的項目根目錄下。代碼在後面提供了,可直接使用。
  6.從新啓動VSCode,就能夠正常使用上Eslint插件啦。
  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 }
.eslintrc.json
相關文章
相關標籤/搜索