|
| 1 | +// ESLint flat config(最小规则集): |
| 2 | +// - 基础:@eslint/js recommended + typescript-eslint recommended(非 type-checked 档, |
| 3 | +// 全量 type-checked 需要项目服务且更慢,当前收益不足以引入); |
| 4 | +// - react-hooks recommended:client 侧是 React 重镇,依赖数组豁免注释 |
| 5 | +// (react-hooks/exhaustive-deps)由此规则消费; |
| 6 | +// - globals 按运行域分治:client bundle → browser,host/脚本 → node,tests → 混合。 |
| 7 | +import js from '@eslint/js' |
| 8 | +import globals from 'globals' |
| 9 | +import reactHooks from 'eslint-plugin-react-hooks' |
| 10 | +import tseslint from 'typescript-eslint' |
| 11 | + |
| 12 | +export default tseslint.config( |
| 13 | + // 构建产物 / 工具目录不参与 lint(node_modules 与点开头目录默认也不进)。 |
| 14 | + { |
| 15 | + ignores: [ |
| 16 | + 'lib/', |
| 17 | + 'dist/', |
| 18 | + 'coverage/', |
| 19 | + 'registry/', |
| 20 | + 'playwright-report/', |
| 21 | + 'test-results/', |
| 22 | + 'node_modules/', |
| 23 | + '.worktrees/', |
| 24 | + ], |
| 25 | + }, |
| 26 | + |
| 27 | + js.configs.recommended, |
| 28 | + tseslint.configs.recommended, |
| 29 | + reactHooks.configs.flat.recommended, |
| 30 | + |
| 31 | + // react-hooks v7 的 recommended 捆绑了 React Compiler 语义规则(purity / |
| 32 | + // immutability / refs / set-state-in-effect 等):本仓库对 CodeMirror / xterm |
| 33 | + // 等命令式集成大量依赖 render 期读 ref、effect 内同步 setState 的既有模式, |
| 34 | + // 57 处存量报错均为噪音级误报,先整体关闭该档,只保留经典双规则 |
| 35 | + // (rules-of-hooks / exhaustive-deps——后者消费代码里带理由的豁免注释)。 |
| 36 | + { |
| 37 | + rules: Object.fromEntries( |
| 38 | + [ |
| 39 | + 'config', |
| 40 | + 'error-boundaries', |
| 41 | + 'gating', |
| 42 | + 'globals', |
| 43 | + 'immutability', |
| 44 | + 'incompatible-library', |
| 45 | + 'preserve-manual-memoization', |
| 46 | + 'purity', |
| 47 | + 'refs', |
| 48 | + 'set-state-in-effect', |
| 49 | + 'static-components', |
| 50 | + 'unsupported-syntax', |
| 51 | + 'use-memo', |
| 52 | + ].map(rule => [`react-hooks/${rule}`, 'off']), |
| 53 | + ), |
| 54 | + }, |
| 55 | + |
| 56 | + // 孤儿 eslint-disable 注释(规则未实际触发)直接报错,防止豁免残留。 |
| 57 | + { linterOptions: { reportUnusedDisableDirectives: 'error' } }, |
| 58 | + |
| 59 | + // no-unused-vars 对齐仓库既有约定:下划线前缀 = 刻意不用的占位(mock 桩等)。 |
| 60 | + { |
| 61 | + rules: { |
| 62 | + '@typescript-eslint/no-unused-vars': ['error', { |
| 63 | + argsIgnorePattern: '^_', |
| 64 | + varsIgnorePattern: '^_', |
| 65 | + caughtErrorsIgnorePattern: '^_', |
| 66 | + }], |
| 67 | + }, |
| 68 | + }, |
| 69 | + |
| 70 | + // client bundle 运行在浏览器(portal 侧边栏 / 各视图 / 拦截层)。 |
| 71 | + { |
| 72 | + files: ['src/client/**/*.{js,mjs,cjs,ts,tsx,jsx}'], |
| 73 | + languageOptions: { globals: globals.browser }, |
| 74 | + }, |
| 75 | + |
| 76 | + // host 侧插件入口与构建/运维脚本跑在 Node。eslint.config.js 自身不 ignore: |
| 77 | + // 它就是一个普通 ESM 脚本,走 js recommended + node globals 正常通过。 |
| 78 | + { |
| 79 | + files: ['src/*.{js,mjs,cjs,ts}', 'scripts/**/*.{js,mjs,cjs,ts}', '*.config.ts', 'eslint.config.js'], |
| 80 | + languageOptions: { globals: globals.node }, |
| 81 | + }, |
| 82 | + |
| 83 | + // tests:Node 里跑(vitest / fs fixtures),jsdom 组件测试又摸浏览器全局。 |
| 84 | + { |
| 85 | + files: ['tests/**/*.{js,mjs,cjs,ts,tsx,jsx}'], |
| 86 | + languageOptions: { globals: { ...globals.node, ...globals.browser } }, |
| 87 | + }, |
| 88 | +) |
0 commit comments