之前多人開發項目,vue-cli3的框架,沒有特別的配置eslint,導致代碼寫的各不相同。最近有時間鼓搗一下。
vue-cli3如何配置eslint
先安插件
eslint-plugin-vue(支持vue規則)
eslint-plugin-node(支持nodejs規則)
eslint-plugin-import(import語句規則)
eslint-plugin-promise
eslint-plugin-html
eslint-plugin-es6
eslint-config-standard包含:
npm install eslint-config-standard eslint-plugin-standard eslint-plugin-promise -g
vue-cli3的eslint在 package.json文件中,我自己的配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
"eslintConfig"
: {
"root"
:
true
,
"env"
: {
"node"
:
true
},
"extends"
: [
"plugin:vue/essential"
,
"standard"
],
"plugins"
: [
"vue"
],
"parserOptions"
: {
"parser"
:
"babel-eslint"
},
"rules"
: {
"prefer-const"
: 0,
"generator-star-spacing"
:
"off"
,
"new-cap"
:
"off"
}
},
|
配置完了之后,看有沒有報錯,少什么包安什么包就是了
vscode配置 (可以看我之前的博客 https://www.cnblogs.com/benbentu/p/9661998.html)
"eslint.autoFixOnSave": true,
注意:eslint檢查,正常vscode檢測,有問題會現現紅色,如果你的沒有出現,看一下,vscode 右下角的eslilnt 是不是被金禁用了,打開就行了

轉載自:https://www.cnblogs.com/benbentu/ 兔兔大海