1.修改 VScode 配置文件,使保存时,自动进行eslint格式化(前提安装了eslint)
点击VSCode页面左下角的设置按钮,选择设置,选择扩展中的Eslint选项,并找到 在 settings.json 中编辑选项。
{
"workbench.colorTheme": "Default Dark+",
"editor.tabSize": 2,
"editor.fontSize": 14,
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
"security.workspace.trust.untrustedFiles": "open",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "vue",
"autoFix": true
}
],
"prettier.eslintIntegration": true,
"prettier.semi": false,
"prettier.singleQuote": true,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-aligned"
}
},
"stylusSupremacy.insertColons": false,
"stylusSupremacy.insertSemicolons": false,
"stylusSupremacy.insertBraces": false,
"stylusSupremacy.insertNewLineAroundImports": false,
"stylusSupremacy.insertNewLineAroundBlocks": false,
"editor.language.brackets": [
],
"eslint.nodeEnv": ""
}
修改项目中的eslint.js格式规则
rules: {
'semi': [2, 'never'], // 不使用分号,否则报错
'quotes': [2, 'single'] // 使用单引号,否则报错
}