Files

57 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

// ESLint 扁平配置(flat config)
// 目标:抓住真正会出问题的东西(未使用变量、隐式 any 之外的常见错误、可选链缺失等),
// 而不与 tsc --strict 的职责重叠,也不与 Prettier 的格式化职责重叠。
import js from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";
export default [
{ ignores: ["dist/**", "release/**", "node_modules/**"] },
js.configs.recommended,
...tseslint.configs.recommended,
{
// 扩展源码 + 测试:浏览器 / Worker 与扩展 API 全局量
files: ["src/**/*.ts", "tests/**/*.js"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
chrome: "readonly",
importScripts: "readonly",
},
},
rules: {
// 类型由 tsc 负责:ESLint 侧关掉会与 tsc 重复或产生大量噪音的规则
"no-undef": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
// 真正的痛点:未使用的变量 / 参数 / 导入
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrors: "none", // 故意忽略异常的 catch 很常见(如探测性调用)
},
],
"no-empty": ["error", { allowEmptyCatch: true }],
"no-var": "error",
"prefer-const": "error",
"no-console": "off", // 项目统一用 debugLog / console.warn,交由 utils.initDebugLog 控制
},
},
{
// 测试文件按 CommonJS 编写(需 require dist/ 下的产物),允许 require
files: ["tests/**/*.js"],
rules: { "@typescript-eslint/no-require-imports": "off" },
},
{
files: ["scripts/**/*.mjs"],
languageOptions: { globals: { ...globals.node } },
},
];