73 lines
3.0 KiB
JavaScript
73 lines
3.0 KiB
JavaScript
|
|
// @ts-check
|
||
|
|
import withNuxt from "./.nuxt/eslint.config.mjs";
|
||
|
|
|
||
|
|
export default withNuxt(
|
||
|
|
// Your custom configs here
|
||
|
|
{
|
||
|
|
rules: {
|
||
|
|
// Vue 规则
|
||
|
|
"vue/multi-word-component-names": "off", // 允许单词组件名
|
||
|
|
"vue/no-v-html": "warn", // v-html 使用时警告
|
||
|
|
"vue/eqeqeq": "error", // 在模板中强制使用 === 和 !==
|
||
|
|
"vue/v-on-event-hyphenation": [
|
||
|
|
"error",
|
||
|
|
"always",
|
||
|
|
{
|
||
|
|
autofix: true, // 自动修复连字符
|
||
|
|
},
|
||
|
|
], // 事件名使用连字符
|
||
|
|
"vue/require-explicit-emits": "error", // 要求显式声明 emits
|
||
|
|
"vue/component-name-in-template-casing": ["error", "kebab-case"], // 组件名使用短横线命名
|
||
|
|
"vue/no-template-shadow": "error", // 禁止模板变量遮蔽
|
||
|
|
"vue/attribute-hyphenation": "error", // 属性名使用连字符
|
||
|
|
"vue/html-end-tags": "error", // HTML 标签必须闭合
|
||
|
|
"vue/html-indent": ["error", 2], // HTML 缩进 2 个空格
|
||
|
|
"vue/max-attributes-per-line": [
|
||
|
|
"error",
|
||
|
|
{
|
||
|
|
singleline: 3, // 单行最多 3 个属性
|
||
|
|
multiline: 1, // 多行每行 1 个属性
|
||
|
|
},
|
||
|
|
], // 每行最多属性数
|
||
|
|
"vue/html-self-closing": [
|
||
|
|
"error",
|
||
|
|
{
|
||
|
|
html: {
|
||
|
|
void: "always", // void 元素必须自闭合
|
||
|
|
normal: "never", // 非元素不自闭合
|
||
|
|
component: "always", // 组件必须自闭合
|
||
|
|
},
|
||
|
|
},
|
||
|
|
], // 自闭合标签规则
|
||
|
|
"vue/singleline-html-element-content-newline": "off", // 允许单行元素内容
|
||
|
|
"vue/multiline-html-element-content-newline": "error", // 多行元素内容需要换行
|
||
|
|
|
||
|
|
// JavaScript/TypeScript 规则
|
||
|
|
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off", // 生产环境警告 console
|
||
|
|
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", // 生产环境警告 debugger
|
||
|
|
"no-unused-vars": ["error", {
|
||
|
|
argsIgnorePattern: "^_",
|
||
|
|
varsIgnorePattern: "^_",
|
||
|
|
}], // 未使用的变量警告
|
||
|
|
"prefer-const": "warn", // 优先使用 const
|
||
|
|
"no-var": "error", // 禁止使用 var
|
||
|
|
|
||
|
|
// 代码风格
|
||
|
|
"semi": ["error", "always"], // 使用分号
|
||
|
|
"quotes": ["error", "double", { avoidEscape: true }], // 使用双引号
|
||
|
|
"comma-dangle": ["error", "always-multiline"], // 多行时允许尾随逗号
|
||
|
|
"arrow-parens": ["error", "as-needed"], // 箭头函数参数括号按需添加
|
||
|
|
"object-curly-spacing": ["error", "always"], // 对象大括号内空格
|
||
|
|
"array-bracket-spacing": ["error", "never"], // 数组方括号内无空格
|
||
|
|
|
||
|
|
// 最佳实践
|
||
|
|
"eqeqeq": ["error", "always"], // 强制使用 === 和 !==
|
||
|
|
"no-duplicate-imports": "error", // 禁止重复导入
|
||
|
|
"no-else-return": "warn", // if-return 后不允许 else
|
||
|
|
"no-nested-ternary": "warn", // 禁止嵌套三元表达式
|
||
|
|
"prefer-template": "warn", // 优先使用模板字符串
|
||
|
|
"no-useless-concat": "error", // 禁止无意义的字符串拼接
|
||
|
|
},
|
||
|
|
},
|
||
|
|
);
|