一套**“不烦人 + 有基本规范 + 适合业务开发”**的 ESLint 配置,适用于 Vue(Vue2 / Vue3 都能用),目标是:几乎不报错,只在关键问题上提醒。
✅ 一、核心思路(你用这套的效果)
- ❌ 不再一堆红
- ⚠️ 重要问题用 warning
- ✅ 保留基本代码质量
- 🧠 不影响开发节奏
🧾 二、完整 .eslintrc.js
直接复制用👇
module.exports = {
root: true,
env: {
node: true,
browser: true
},
extends: [
"eslint:recommended",
"plugin:vue/recommended"
],
parserOptions: {
ecmaVersion: 2020
},
rules: {
/* ================= 基础(全部放宽) ================= */
"no-console": "off",
"no-debugger": "off",
"no-unused-vars": "warn",
"no-undef": "off",
"no-empty": "off",
"no-extra-semi": "off",
/* ================= 风格(基本不限制) ================= */
"indent": "off",
"quotes": "off",
"semi": "off",
"comma-dangle": "off",
/* ================= Vue(重点放宽) ================= */
"vue/multi-word-component-names": "off",
"vue/no-unused-vars": "warn",
"vue/no-mutating-props": "off",
"vue/require-default-prop": "off",
"vue/require-prop-types": "off",
"vue/no-v-html": "off",
"vue/html-self-closing": "off",
/* ================= 常见烦人规则关闭 ================= */
"prefer-const": "off",
"no-var": "off",
"eqeqeq": "off",
"camelcase": "off",
/* ================= 适度保留(防低级错误) ================= */
"no-dupe-keys": "error", // 对象重复key(必须拦)
"no-duplicate-case": "error", // switch重复case
"no-unreachable": "warn", // 死代码
"valid-typeof": "error" // typeof错误
}
};
📁 三、可选:.eslintignore
避免扫描无关文件👇
node_modules/
dist/
build/
*.min.js
⚙️ 四、IDEA 配合(很关键)
否则还是会烦👇
👉 1. 关闭自动修复
Settings → ESLint
取消:Run eslint --fix on save
👉 2. 降低提示级别
Editor → Inspections → ESLint → 改为 Warning 或 No Highlight
🎯 五、这套配置的“行为表现”
| 情况 | 结果 |
|---|---|
| console.log | ✅ 不报 |
| 未使用变量 | ⚠️ 提示(不阻塞) |
| Vue 单词组件名 | ✅ 不管 |
| 格式问题 | ✅ 不管 |
| 重复 key | ❌ 报错(必须改) |
| 死代码 | ⚠️ 提示 |
,目标是:几乎不报错,只在关键问题上提醒&spm=1001.2101.3001.5002&articleId=160399952&d=1&t=3&u=a990c31ad6ab41e2811b5c4bea26d0f0)
1万+

被折叠的 条评论
为什么被折叠?



