市面上常用的格式化插件Prettier,其格式化有自己的风格,可能不满足项目需求,会导致eslint的报错问题,我们期望可以根据项目中的.eslintrc.js文件进行格式化,只需在vscode的settings.json文件的最下方添加四行代码
{
// 默认使用eslint进行格式化
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
// 开启eslint检查
"eslint.format.enable": true,
// 使用eslint来fix,包括格式化会自动fix和代码质量检查会给出错误提示
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}