前置条件:
1.禁用格式化插件 prettier format on save 关闭
2.安装Eslint插件,并配置保存自动修复
"editor.codeActionsOnSave": {
"source.fixAll": true // 保存自动修复
},
// 编辑器设置 - 保存时做格式化
"editor.formatOnSave": false,
基础配置:
在.eslintrc.cjs文件中配置
rules: {
'prettier/prettier': [
'warn',
{
singleQuote: true, // 单引号
semi: false, // 无分号
printwidth: 80, // 每行宽度至多80字符
trailingComma: 'none', // 不假对象|数组最后逗号
endOfLine: 'auto' // 换行符号不限制 (win mac 不一致)
}
],
'vue/multi-word-component-names': [
'warn',
{
ignores: ['index'] // vue组件名称多单词组成(忽略index.vue)
}
],
'vue/no-setup-props-destructure': ['off'], // 关闭props结构校验
'no-undef': 'error' // 添加未定义变量错误提示
}