vue-cli下ESlint 報錯解決(工具是webstorm)2018.07.18更新
阿新 • • 發佈:2019-01-09
#
#
最近在使用 vue-cli ,安裝了eslint。之前還是好好的,就是這一次開始報錯了。報錯顯示:expected indentation of 0 spaces but found 0 spaces
1、剛開始查看了下,以為是webstorm的程式碼格式化與 eslint 的程式碼規範不一致,但是查看了下:兩者是一樣的;所以不是這個原因,繼續排查。
2、繼續排查:我於是查看了eslint 的配置檔案,我好奇為啥之前的專案沒有報錯,現在的居然報錯。於是對比了之前專案的.exlintrc.js 和 現在專案的 .eslintrc.js 檔案。發現果然這兩個檔案,有變動。
注意:同時還要安裝npm eslint-html-plugin –save-dev外掛
3、.eslintrc.js 詳細備註:
這是編寫eslint規則的檔案
module.exports = {
// 預設情況下,ESLint會在所有父級元件中尋找配置檔案,一直到根目錄。ESLint一旦發現配置檔案中有 "root": true,它就會停止在父級目錄中尋找。
root: true,
// 對Babel解析器的包裝使其與 ESLint 相容。
parser: 'babel-eslint',
parserOptions: {
// 程式碼是 ECMAScript 模組
sourceType: 'module'
},
env: {
// 預定義的全域性變數,這裡是瀏覽器環境
browser: true,
},
// 擴充套件一個流行的風格指南,即 eslint-config-standard
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.vue files
plugins: [
// 此外掛用來識別.html 和 .vue檔案中的js程式碼
'html',
// standard風格的依賴包
"standard",
// standard風格的依賴包
"promise"
],
//配置的一些規則
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}
2018.07.18注意:以下是我嘗試的方法。
- 我排查的方式:
- 單獨修改.eslintrc.js的plugin規則,以及rules規則,都沒用。包括在eslintrc.js的rules新增的”indent”: [2, 4],//縮排風格,還是沒用。
- 修改webstrom的程式設計程式碼的風格,還是沒用
- 修改.editorconfig檔案的縮排配置,還是沒用
2018.07.18更新
最近,在使用eslint的時候,又報錯了。最終解決方案如下:
將package.json中的關於eslint的最新配置刪掉,換成之前的舊版本的eslint相關配置。同時在eslintrc.js中的rulus規則中新增’html’(不懂的見本文章前面)
將 "eslint": "^4.15.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.0.0",
替換為:
"eslint": "^3.19.0",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.0",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",