From 34c6ac1cf5cad8c93f2bd73ec34ee798f3d3103c Mon Sep 17 00:00:00 2001 From: Timi Date: Mon, 24 Nov 2025 11:23:02 +0800 Subject: [PATCH] add eslint --- .eslintignore | 15 +++++++++ .eslintrc.cjs | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc.cjs diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..acb314d --- /dev/null +++ b/.eslintignore @@ -0,0 +1,15 @@ +*.sh +node_modules +*.md +*.woff +*.ttf +.vscode +.idea +dist +/public +/docs +.husky +.local +.eslintrc.cjs +dist +pnpm-lock.yaml diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..f88b2d3 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,87 @@ +module.exports = { + root: true, + env: { + browser: true, + es2021: true, + node: true + }, + extends: [ + "eslint:recommended", + "plugin:vue/vue3-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], + overrides: [ + { + env: { + node: true + }, + files: [".eslintrc.{js,cjs}"], + parserOptions: { + sourceType: "script" + } + } + ], + parser: "vue-eslint-parser", + parserOptions: { + parser: "@typescript-eslint/parser", + sourceType: "module" + }, + settings: { + "import/resolver": { + alias: { + map: [["@", "./src/renderer"]], + extensions: [".ts", ".js", ".vue", ".json"] + } + } + }, + plugins: ["vue", "@typescript-eslint"], + rules: { // 注释是描述使用该设置的效果 + "vue/attribute-hyphenation": "off", + "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", + "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", + // 其他 + "camelcase": 2, // 变量驼峰式命名 + "quotes": ["error", "double"], // 强制双引字符串 + "eqeqeq": ["error", "always"], // 强制全等比较 + "semi": ["error", "always"], // 强制语句分号结束 + "max-len": [ + "error", + { + "code": 180 + } + ], + // 逗号 + "comma-style": [2, "last"], // 逗号出现在行末 [first, last] + "comma-dangle": [2, "never"], // 数组或对象不可带最后一个逗号 [never, always, always-multiline] + // 空格 + "no-trailing-spaces": "error", // 禁止行末存在空格 + "comma-spacing": [2, { "before": false, "after": true }], // 逗号后需要空格 + "semi-spacing": ["error", { "before": false, "after": true }], // 分号后需要空格 + "computed-property-spacing": [2, "never"], // 以方括号取对象属性时,[ 后面和 ] 前面需要空格, [never, always] + "space-before-function-paren": ["error", { // 函数括号前空格 + "anonymous": "always", // 针对匿名函数表达式,比如 function () {} + "named": "never", // 针对命名函数表达式,比如 function foo() {} + "asyncArrow": "always" // 针对异步的箭头函数表达式,比如 async () => {} + }], + // 缩进 + "no-mixed-spaces-and-tabs": "off", // 允许混合缩进 + "no-tabs": ["error", { allowIndentationTabs: true }], // 使用 Tab 缩进 + "indent": ["error", "tab", { // Tab 缩进相关 + SwitchCase: 1 // Switch Case 缩进一级 + }], + // 框架 + "@typescript-eslint/ban-types": "off", // TS 允许空对象 + "@typescript-eslint/no-empty-function": "off", // TS 允许空函数 + "@typescript-eslint/no-explicit-any": "off", // TS 允许 any 类型 + "@typescript-eslint/explicit-module-boundary-types": "off", // TS 允许显式模块边界类型? + "vue/no-multiple-template-root": "off", // Vue3 支持多个根节点 + "@typescript-eslint/no-this-alias": "off", // 允许 this 变量本地化 + "vue/no-v-model-argument": "off", // 允许 v-model 支持参数 + "vue/multi-word-component-names": "off", // 允许单个词语的组件名 + "@typescript-eslint/no-unused-expressions": [ // 允许逻辑与(&&)、逻辑或(||)短路 + "error", + { "allowShortCircuit": true } + ] + } +};