fix: 替换 eslint-plugin-import 为 eslint-plugin-import-x,解决与 ESLint 10 的依赖冲突
- eslint-plugin-import@2.32.0 peerDependency 仅支持 ESLint ^2-^9,与项目 eslint@10.4.1 不兼容 - eslint-import-resolver-alias 依赖链会间接拉回旧版 eslint-plugin-import,形成连锁冲突 - 移除 eslint-plugin-import 和 eslint-import-resolver-alias,改用 eslint-plugin-import-x@^4.16.1 - eslint.config.js 使用内置 createNodeResolver() 替代外部 resolver,@ 别名改用绝对路径解析
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
/* eslint-env node */
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import globals from "globals";
|
||||
import pluginVue from "eslint-plugin-vue";
|
||||
import parserVue from "vue-eslint-parser";
|
||||
import importPlugin from "eslint-plugin-import";
|
||||
import importPlugin, { createNodeResolver } from "eslint-plugin-import-x";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export default [
|
||||
{
|
||||
@@ -29,31 +33,31 @@ export default [
|
||||
},
|
||||
|
||||
plugins: {
|
||||
import: importPlugin,
|
||||
"import-x": importPlugin,
|
||||
},
|
||||
|
||||
rules: {
|
||||
// 确保导入的模块实际存在(核心规则,防止构建失败)
|
||||
"import/no-unresolved": "error",
|
||||
"import-x/no-unresolved": "error",
|
||||
// 确保导入的命名导出实际存在
|
||||
"import/named": "error",
|
||||
"import-x/named": "error",
|
||||
// 确保默认导出存在
|
||||
"import/default": "error",
|
||||
"import-x/default": "error",
|
||||
// 确保命名空间导出存在
|
||||
"import/namespace": "error",
|
||||
"import-x/namespace": "error",
|
||||
// Vue 相关规则
|
||||
"vue/multi-word-component-names": "off",
|
||||
},
|
||||
|
||||
settings: {
|
||||
"import/resolver": {
|
||||
alias: {
|
||||
map: [
|
||||
["@", "./src"],
|
||||
],
|
||||
extensions: [".js", ".jsx", ".vue"],
|
||||
},
|
||||
},
|
||||
"import-x/resolver-next": [
|
||||
createNodeResolver({
|
||||
alias: {
|
||||
"@": [path.join(__dirname, "src")],
|
||||
},
|
||||
extensions: [".mjs", ".cjs", ".js", ".jsx", ".vue", ".json", ".node"],
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -75,8 +75,7 @@
|
||||
"@vitejs/plugin-vue": "^5.2.4",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"eslint": "^10.4.1",
|
||||
"eslint-import-resolver-alias": "^1.1.2",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-import-x": "^4.16.1",
|
||||
"eslint-plugin-vue": "^10.9.1",
|
||||
"globals": "^17.5.0",
|
||||
"happy-dom": "^20.8.3",
|
||||
|
||||
Reference in New Issue
Block a user