在vue的配置文件.eslintrc.js中配置以下選項 這樣只需要右鍵格式化以下文件夾,大部分eslint規(guī)則報錯就會被干掉了
// https://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
env: {
browser: true,
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// js語句結(jié)尾必須使用 ;
// 'semi': ['off', 'always'],
'semi': ['error', 'always'],
// 三等號
'eqeqeq': 0,
// 強制在注釋中 // 或 /* 使用一致的空格
'spaced-comment': 0,
// 關(guān)鍵字后面使用一致的空格
'keyword-spacing': 0,
// 強制在 function的左括號之前使用一致的空格
'space-before-function-paren': 0,
// 引號類型
"quotes": [0, "single"],
"vue/no-parsing-error": [2, { "x-invalid-end-tag": false }]
}
}
另外如果有些文件不想被eslint檢測可以在.eslintignore文件夾中這樣配置
build/*
config/*
test/*
src/store/*
src/utils/*
src/router/*
src/personalCenter/view/orders/info.vue
最后給大家一個eslint規(guī)則的api,方便大家開發(fā)
http://eslint.cn/docs/rules/