vscode eslint 自动保存
vscode安装插件Prettier - JavaScript formatter和vetur
File -> Preference -> Settings(如果装了中文插件包应该是 文件 -> 选项 -> 用户),搜索 eslint,点击 Edit in setting.json
最新版本只需添加
{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true, }, }
添加后 ,Ctrl+s保存会自动按照你的项目建的eslintrc.js文件的规则修复
我的eslintrc.js内容:
module.exports = { settings: { "import/resolver": { webpack: { config: './build/webpack.base.conf.js' } } }, "env": { "browser": true, "es6": true }, "extends": [ "plugin:vue/base", "airbnb-base", ], "globals": { }, "parserOptions": { "parser": "babel-eslint", // "ecmaVersion": 2018, // "sourceType": "module", }, plugins: [ "vue", ], "rules": { "no-unused-vars": "warn", "import/extensions": "warn", "import/no-extraneous-dependencies": [2, { "devDependencies": true }], "import/no-unresolved": [2, { "ignore": ["antd-mobile"] }], "no-param-reassign": "warn", "max-len": ["error", { "code": 120 }], "vue/no-parsing-error": "warn", "arrow-parens": "off", "consistent-return": "off", "no-else-return": "off", "prefer-destructuring": "off", "strict": "off", "linebreak-style": "off", "prefer-template": "off", "no-unreachable": "off", } };