- 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,@ 别名改用绝对路径解析
64 lines
1.6 KiB
JavaScript
Executable File
64 lines
1.6 KiB
JavaScript
Executable File
/* 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, { createNodeResolver } from "eslint-plugin-import-x";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
export default [
|
|
{
|
|
name: "app/files-to-lint",
|
|
files: ["**/*.{js,mjs,jsx,vue}"],
|
|
},
|
|
|
|
{
|
|
name: "app/files-to-ignore",
|
|
ignores: ["**/dist/**", "**/node_modules/**", "**/help-center/**"],
|
|
},
|
|
|
|
...pluginVue.configs["flat/recommended"],
|
|
|
|
{
|
|
languageOptions: {
|
|
globals: {
|
|
...globals.browser,
|
|
...globals.node,
|
|
},
|
|
parser: parserVue,
|
|
ecmaVersion: "latest",
|
|
sourceType: "module",
|
|
},
|
|
|
|
plugins: {
|
|
"import-x": importPlugin,
|
|
},
|
|
|
|
rules: {
|
|
// 确保导入的模块实际存在(核心规则,防止构建失败)
|
|
"import-x/no-unresolved": "error",
|
|
// 确保导入的命名导出实际存在
|
|
"import-x/named": "error",
|
|
// 确保默认导出存在
|
|
"import-x/default": "error",
|
|
// 确保命名空间导出存在
|
|
"import-x/namespace": "error",
|
|
// Vue 相关规则
|
|
"vue/multi-word-component-names": "off",
|
|
},
|
|
|
|
settings: {
|
|
"import-x/resolver-next": [
|
|
createNodeResolver({
|
|
alias: {
|
|
"@": [path.join(__dirname, "src")],
|
|
},
|
|
extensions: [".mjs", ".cjs", ".js", ".jsx", ".vue", ".json", ".node"],
|
|
}),
|
|
],
|
|
},
|
|
},
|
|
];
|