From 2284d17738474f2bd88a30f5ae81450411f9a10a Mon Sep 17 00:00:00 2001 From: abulo Date: Wed, 3 Jul 2024 09:20:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20perf?= =?UTF-8?q?=F0=9F=91=8C:=20=E5=8D=87=E7=BA=A7=E5=89=8D=E7=AB=AF=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E5=BA=93&=E5=8D=87=E7=BA=A7eslint=E5=88=B0=209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 15 - .eslintrc.cjs | 11 +- .prettierrc.cjs | 2 +- .vscode/settings.json | 3 +- eslint.config.js | 207 ++ package.json | 40 +- pnpm-lock.yaml | 2102 +++++++++-------- src/components/ImportExcel/index.vue | 3 +- .../ProTable/components/Pagination.vue | 3 +- .../ProTable/components/TableColumn.vue | 3 +- src/components/ProTable/index.vue | 15 +- .../SearchForm/components/SearchFormItem.vue | 6 +- src/components/SelectFilter/index.vue | 3 +- src/components/SelectIcon/index.vue | 3 +- src/components/TreeFilter/index.vue | 3 +- src/components/Upload/Img.vue | 3 +- src/components/Upload/Imgs.vue | 3 +- src/components/WangEditor/index.vue | 3 +- src/layouts/LayoutClassic/index.vue | 3 +- src/layouts/LayoutColumns/index.vue | 6 +- src/layouts/LayoutVertical/index.vue | 3 +- .../Header/components/AssemblySize.vue | 3 +- .../Header/components/Breadcrumb.vue | 3 +- .../components/Header/components/Language.vue | 3 +- .../Header/components/SearchMenu.vue | 6 +- src/views/assembly/draggable/index.vue | 3 +- src/views/assembly/guide/index.vue | 3 +- src/views/assembly/svgIcon/index.vue | 3 +- src/views/assembly/treeFilter/index.vue | 6 +- src/views/assembly/uploadFile/index.vue | 6 +- src/views/auth/button/index.vue | 3 +- src/views/auth/menu/index.vue | 3 +- src/views/form/dynamicForm/index.vue | 6 +- src/views/form/proForm/index.vue | 3 +- src/views/proTable/complexProTable/index.vue | 3 +- src/views/proTable/components/UserDrawer.vue | 3 +- src/views/proTable/treeProTable/index.vue | 6 +- src/views/proTable/useProTable/index.vue | 3 +- src/views/proTable/useSelectFilter/index.vue | 6 +- src/views/proTable/useTreeFilter/index.vue | 6 +- tsconfig.json | 3 +- vite.config.ts | 6 + 42 files changed, 1369 insertions(+), 1158 deletions(-) delete mode 100644 .eslintignore create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 2debdc3f..00000000 --- a/.eslintignore +++ /dev/null @@ -1,15 +0,0 @@ -*.sh -node_modules -*.md -*.woff -*.ttf -.vscode -.idea -dist -/public -/docs -.husky -.local -/bin -/src/mock/* -stats.html diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 644cf14d..e1167cbb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -50,7 +50,16 @@ module.exports = { "vue/v-slot-style": "error", // 强制执行 v-slot 指令样式 "vue/no-mutating-props": "error", // 不允许改变组件 prop "vue/custom-event-name-casing": "error", // 为自定义事件名称强制使用特定大小写 - "vue/html-closing-bracket-newline": "error", // 在标签的右括号之前要求或禁止换行 + "vue/singleline-html-element-content-newline": "off", // 在单行元素的内容前后需要换行符 + "vue/attributes-order": "off", // 强制执行属性顺序 + "vue/require-default-prop": "off", // 此规则要求为每个 prop 为必填时,必须提供默认值 + "vue/html-closing-bracket-newline": [ + "off", + { + singleline: "never", + multiline: "always" + } + ], // 在标签的右括号之前要求或禁止换行 "vue/attribute-hyphenation": "error", // 对模板中的自定义组件强制执行属性命名样式:my-prop="prop" "vue/attributes-order": "off", // vue api使用顺序,强制执行属性顺序 "vue/no-v-html": "off", // 禁止使用 v-html diff --git a/.prettierrc.cjs b/.prettierrc.cjs index f03e02fc..f1124bb5 100644 --- a/.prettierrc.cjs +++ b/.prettierrc.cjs @@ -20,7 +20,7 @@ module.exports = { // 在对象,数组括号与文字之间加空格 "{ foo: bar }" (true:有,false:没有) bracketSpacing: true, // 将 > 多行元素放在最后一行的末尾,而不是单独放在下一行 (true:放末尾,false:单独一行) - bracketSameLine: false, + bracketSameLine: true, // (x) => {} 箭头函数参数只有一个时是否要有小括号 (avoid:省略括号,always:不省略括号) arrowParens: "avoid", // 指定要使用的解析器,不需要写文件开头的 @prettier diff --git a/.vscode/settings.json b/.vscode/settings.json index 909951ae..441e9d3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -93,5 +93,6 @@ "yiwen", "zhongyingwen", "zhuti" - ] + ], + "i18n-ally.localesPaths": ["src/languages"] } diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..dc436825 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,207 @@ +import js from "@eslint/js"; +import pluginVue from "eslint-plugin-vue"; +import * as parserVue from "vue-eslint-parser"; +import configPrettier from "eslint-config-prettier"; +import pluginPrettier from "eslint-plugin-prettier"; +import { defineFlatConfig } from "eslint-define-config"; +import * as parserTypeScript from "@typescript-eslint/parser"; +import pluginTypeScript from "@typescript-eslint/eslint-plugin"; + +export default defineFlatConfig([ + { + ...js.configs.recommended, + ignores: ["**/.*", "dist/*", "*.d.ts", "public/*", "src/assets/**", "src/**/iconfont/**"], + languageOptions: { + globals: { + // index.d.ts + RefType: "readonly", + EmitType: "readonly", + TargetContext: "readonly", + ComponentRef: "readonly", + ElRef: "readonly", + ForDataType: "readonly", + AnyFunction: "readonly", + PropType: "readonly", + Writable: "readonly", + Nullable: "readonly", + NonNullable: "readonly", + Recordable: "readonly", + ReadonlyRecordable: "readonly", + Indexable: "readonly", + DeepPartial: "readonly", + Without: "readonly", + Exclusive: "readonly", + TimeoutHandle: "readonly", + IntervalHandle: "readonly", + Effect: "readonly", + ChangeEvent: "readonly", + WheelEvent: "readonly", + ImportMetaEnv: "readonly", + Fn: "readonly", + PromiseFn: "readonly", + ComponentElRef: "readonly", + parseInt: "readonly", + parseFloat: "readonly" + } + }, + plugins: { + prettier: pluginPrettier + }, + rules: { + ...configPrettier.rules, + ...pluginPrettier.configs.recommended.rules, + "no-var": "error", // 要求使用 let 或 const 而不是 var + "no-multiple-empty-lines": ["error", { max: 1 }], // 不允许多个空行 + "prefer-const": "off", // 使用 let 关键字声明但在初始分配后从未重新分配的变量,要求使用 const + "no-use-before-define": "off" // 禁止在 函数/类/变量 定义之前使用它们 + // "no-debugger": "off", + // "no-unused-vars": [ + // "error", + // { + // argsIgnorePattern: "^_", + // varsIgnorePattern: "^_" + // } + // ], + // "prettier/prettier": [ + // "error", + // { + // endOfLine: "auto" + // } + // ] + } + }, + { + files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"], + languageOptions: { + parser: parserTypeScript, + parserOptions: { + sourceType: "module" + } + }, + plugins: { + "@typescript-eslint": pluginTypeScript + }, + rules: { + ...pluginTypeScript.configs.strict.rules, + "@typescript-eslint/no-unused-vars": "error", // 禁止定义未使用的变量 + "@typescript-eslint/no-empty-function": "error", // 禁止空函数 + "@typescript-eslint/prefer-ts-expect-error": "error", // 禁止使用 @ts-ignore + "@typescript-eslint/ban-ts-comment": "error", // 禁止 @ts- 使用注释或要求在指令后进行描述 + "@typescript-eslint/no-inferrable-types": "off", // 可以轻松推断的显式类型可能会增加不必要的冗长 + "@typescript-eslint/no-namespace": "off", // 禁止使用自定义 TypeScript 模块和命名空间 + "@typescript-eslint/no-explicit-any": "off", // 禁止使用 any 类型 + "@typescript-eslint/ban-types": "off", // 禁止使用特定类型 + "@typescript-eslint/no-var-requires": "off", // 允许使用 require() 函数导入模块 + "@typescript-eslint/no-non-null-assertion": "off" // 不允许使用后缀运算符的非空断言(!) + // "@typescript-eslint/ban-types": "off", + // "@typescript-eslint/no-redeclare": "error", + // "@typescript-eslint/ban-ts-comment": "off", + // "@typescript-eslint/no-explicit-any": "off", + // "@typescript-eslint/prefer-as-const": "warn", + // "@typescript-eslint/no-empty-function": "off", + // "@typescript-eslint/no-non-null-assertion": "off", + // "@typescript-eslint/no-import-type-side-effects": "error", + // "@typescript-eslint/explicit-module-boundary-types": "off", + // "@typescript-eslint/no-namespace": "off", + // "@typescript-eslint/consistent-type-imports": [ + // "error", + // { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" } + // ], + // "@typescript-eslint/prefer-literal-enum-member": ["error", { allowBitwiseExpressions: true }], + // "@typescript-eslint/no-unused-vars": [ + // "error", + // { + // argsIgnorePattern: "^_", + // varsIgnorePattern: "^_" + // } + // ] + } + }, + { + files: ["**/*.d.ts"], + rules: { + "eslint-comments/no-unlimited-disable": "off", + "import/no-duplicates": "off", + "unused-imports/no-unused-vars": "off" + } + }, + // { + // files: ["**/*.?([cm])js"], + // rules: { + // "@typescript-eslint/no-require-imports": "off", + // "@typescript-eslint/no-var-requires": "off" + // } + // }, + { + files: ["**/*.vue"], + languageOptions: { + globals: { + $: "readonly", + $$: "readonly", + $computed: "readonly", + $customRef: "readonly", + $ref: "readonly", + $shallowRef: "readonly", + $toRef: "readonly" + }, + parser: parserVue, + parserOptions: { + ecmaFeatures: { + jsx: true + }, + extraFileExtensions: [".vue"], + parser: "@typescript-eslint/parser", + sourceType: "module" + } + }, + plugins: { + vue: pluginVue + }, + processor: pluginVue.processors[".vue"], + rules: { + ...pluginVue.configs.base.rules, + ...pluginVue.configs["vue3-essential"].rules, + ...pluginVue.configs["vue3-recommended"].rules, + // vue (https://eslint.vuejs.org/rules) + "vue/script-setup-uses-vars": "error", // 防止