/** * ESLint A11y 配置(P6 硬化,flat config 格式 / ESLint 9) * * - 配置 eslint-plugin-jsx-a11y(WCAG 2.2 AA 规则集) * - 5 个核心页面(grades/grades-entry/homework-detail/questions/settings)强制 error 级别 * - 其他页面降级为 warn(遗留代码渐进式迁移) * - eslint 在仅有 warning 时退出码为 0 * * 这是独立配置文件(flat config 数组格式),不修改主 eslint 配置。 * 使用方式:eslint -c .eslintrc.a11y.js src * * 关联:02-architecture-design.md §12 可观测性 / WCAG 2.2 AA */ // 使用 @typescript-eslint/parser 以支持 TS/TSX 语法 // (通过 Node.js 向上查找从根 node_modules 解析) let tsParser; try { tsParser = require("@typescript-eslint/parser"); } catch { tsParser = undefined; } // 加载 jsx-a11y 插件(从根 node_modules 解析) let jsxA11y; try { jsxA11y = require("eslint-plugin-jsx-a11y"); } catch { jsxA11y = { rules: {} }; } /** @type {import('eslint').Linter.Config[]} */ module.exports = [ { files: ["**/*.{ts,tsx,js,jsx}"], languageOptions: { parser: tsParser, ecmaVersion: 2022, sourceType: "module", parserOptions: { ecmaFeatures: { jsx: true }, }, }, plugins: { "jsx-a11y": jsxA11y }, rules: { // WCAG 2.2 AA 规则集 // 1.1.1 非文本内容:所有图片必须有 alt 属性 "jsx-a11y/alt-text": "error", // 1.3.1 信息与关系:表单控件必须有 label // 降级为 warn:control-has-associated-label 不识别