1.vscode安装eslint
2.在文件–首选项–设置–setting
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": true,
"eslint.format.enable": true,
"editor.formatOnType": true,
"eslint.options": {}
3.再去配置eslint
1.在安装vue项目后,可再次安装eslint
npx eslint --init
2.在生成的.eslintrc.js文件中配置
module.exports = {
"root": true,
"extends": [
"eslint:recommended",
"plugin:vue/essential"
],
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"no-console": "off",
"no-unused-vars": ["error", {"argsIgnorePattern": "resp?"}],
"space-infix-ops": "error",
"space-unary-ops": "error",
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"comma-dangle": "error",
"comma-spacing": "error",
"computed-property-spacing": "error",
"indent": ["error", 4, {
"SwitchCase": 1,
"MemberExpression": "off"
}],
"max-depth": ["error", 3],
"max-len": ["error", 260],
"no-mixed-spaces-and-tabs": "error",
"vue/no-parsing-error": ["error", { "x-invalid-end-tag": false }]
}
}
4.命令行修复eslint
npx vue-cli-service lint --fix
最新配置
module.exports = {
root: true,
extends: [
'plugin:vue/essential',
'standard'
],
env: {
browser: true,
commonjs: true,
es6: true,
node: true
},
parserOptions: {
parser: 'babel-eslint'
},
rules: {
}
}