76 lines
2.6 KiB
JavaScript
76 lines
2.6 KiB
JavaScript
// ESLint flat config(ESLint 9)。防回潮基建:锁定去重/抽取/合规成果,约束新代码。
|
||
// 策略:warn 基线——历史问题(如 exhaustive-deps)设 warn 不阻断提交,
|
||
// 新代码的 error 类问题(unused vars 等)强制清零。CI/pre-commit 只拦 error。
|
||
import js from "@eslint/js";
|
||
import tseslint from "typescript-eslint";
|
||
import reactHooks from "eslint-plugin-react-hooks";
|
||
import reactRefresh from "eslint-plugin-react-refresh";
|
||
import unusedImports from "eslint-plugin-unused-imports";
|
||
import globals from "globals";
|
||
|
||
export default tseslint.config(
|
||
{
|
||
// 忽略构建产物、依赖、配置脚本、JS shim。
|
||
ignores: [
|
||
"dist/**",
|
||
"node_modules/**",
|
||
"coverage/**",
|
||
"**/*.config.{js,ts,mjs,cjs}",
|
||
"scripts/**",
|
||
"src/data/ossAssets.js",
|
||
],
|
||
},
|
||
js.configs.recommended,
|
||
...tseslint.configs.recommended,
|
||
{
|
||
files: ["**/*.{ts,tsx}"],
|
||
languageOptions: {
|
||
ecmaVersion: 2022,
|
||
sourceType: "module",
|
||
globals: {
|
||
...globals.browser,
|
||
...globals.es2022,
|
||
},
|
||
},
|
||
plugins: {
|
||
"react-hooks": reactHooks,
|
||
"react-refresh": reactRefresh,
|
||
"unused-imports": unusedImports,
|
||
},
|
||
rules: {
|
||
...reactHooks.configs.recommended.rules,
|
||
// 历史问题:warn 不阻断,渐进清理。
|
||
"react-hooks/exhaustive-deps": "warn",
|
||
"@typescript-eslint/no-explicit-any": "warn",
|
||
// 未使用 import:error 且可 autofix 自动删除(unused-imports 插件专长)。
|
||
"@typescript-eslint/no-unused-vars": "off",
|
||
"unused-imports/no-unused-imports": "error",
|
||
// 未使用局部变量:warn 基线(不自动删,避免误删 dead code 有副作用的赋值)。
|
||
"unused-imports/no-unused-vars": [
|
||
"warn",
|
||
{ vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" },
|
||
],
|
||
// 允许 warn/error(现有 console.warn/error 是有意的诊断输出)。
|
||
"no-console": ["warn", { allow: ["warn", "error"] }],
|
||
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
|
||
},
|
||
},
|
||
{
|
||
// 测试文件:补 vitest 全局,避免 describe/it/expect 误报未定义。
|
||
files: ["**/*.{test,spec}.{ts,tsx}"],
|
||
languageOptions: {
|
||
globals: {
|
||
...globals.node,
|
||
describe: "readonly",
|
||
it: "readonly",
|
||
expect: "readonly",
|
||
vi: "readonly",
|
||
beforeEach: "readonly",
|
||
afterEach: "readonly",
|
||
beforeAll: "readonly",
|
||
afterAll: "readonly",
|
||
},
|
||
},
|
||
},
|
||
);
|