这里默认项目已经引入了eslint并且vscode引入了eslint插件,下面只描述vscode 开启保存时调用eslint进行格式化方法。
1、打开settings.json 打开方法参考https://www.jb51.net/softjc/730336.html
2、在settgings中添加如下配置
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
}
注:其实不建议配置保存自动格式化,文件多了之后每次保存编辑器都会很卡。提交前做校验是比较合适的,当然这回导致在提交的时候需要较长时间