import js from "@eslint/js"; import tseslint from "typescript-eslint"; import reactHooks from "eslint-plugin-react-hooks"; import jsxA11y from "eslint-plugin-jsx-a11y"; import prettier from "eslint-config-prettier"; export default tseslint.config( { ignores: ["dist/**", "dist-stats/**", "node_modules/**", "playwright-report/**", "test-results/**"] }, js.configs.recommended, ...tseslint.configs.recommended, // react-hooks 插件的 flat 导出名随版本而异(recommended-latest / configs.flat.recommended), // 以安装版本实际导出为准,用 npx eslint --print-config src/main.tsx 验证规则已生效 reactHooks.configs.flat["recommended-latest"], jsxA11y.flatConfigs.recommended, { files: ["**/*.{ts,tsx}"], rules: { "@typescript-eslint/no-unused-vars": [ "error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" }, ], }, }, { // 旧阅读器 chrome 的点击区/交互元素将被 ② 阅读器改版迁入 radix 原语, // 届时收严为 error;本期对存量文件降 warn(spec S1 决策) files: [ "src/readers/**/*.tsx", "src/components/Bookmarks.tsx", "src/components/reader-nav.tsx", "src/components/rd-slider.tsx", "src/pages/Reader.tsx", ], rules: { "jsx-a11y/click-events-have-key-events": "warn", "jsx-a11y/no-static-element-interactions": "warn", "jsx-a11y/no-noninteractive-element-interactions": "warn", }, }, { files: ["e2e/**/*.ts"], // e2e 是 Playwright 脚本,测试工具链的动态类型用法(如 locator/fixture 包装)允许 any languageOptions: { globals: { process: "readonly", console: "readonly", URL: "readonly" } }, rules: { "@typescript-eslint/no-explicit-any": "off" }, }, { files: ["**/*.test.{ts,tsx}", "test/**/*.ts"], // 测试代码允许 any 以贴合测试惯例(mock 数据、运行时探测) rules: { "@typescript-eslint/no-explicit-any": "off" }, }, prettier, // 必须最后:关闭所有与 prettier 冲突的格式规则 );