最近折騰了一番,總算把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 }