91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
// admin-portal ESLint flat config
|
||
// 包含 React + jsx-a11y + TypeScript 规则
|
||
// 注意:@next/eslint-plugin-next 14.x 与 ESLint 9 不兼容,暂不使用
|
||
const js = require('@eslint/js');
|
||
const tseslint = require('typescript-eslint');
|
||
const prettierConfig = require('eslint-config-prettier');
|
||
const jsx11y = require('eslint-plugin-jsx-a11y');
|
||
|
||
module.exports = tseslint.config(
|
||
// 全局忽略
|
||
{
|
||
ignores: [
|
||
'.next/**',
|
||
'coverage/**',
|
||
'node_modules/**',
|
||
'public/mockServiceWorker.js',
|
||
'eslint.config.js',
|
||
'next.config.js',
|
||
'vitest.config.ts',
|
||
'postcss.config.js',
|
||
'tailwind.config.js',
|
||
],
|
||
},
|
||
|
||
// 基础 JS 规则
|
||
js.configs.recommended,
|
||
|
||
// TypeScript 规则
|
||
...tseslint.configs.recommended,
|
||
|
||
// jsx-a11y 规则(A11y WCAG 2.2 AA)
|
||
{
|
||
plugins: {
|
||
'jsx-a11y': jsx11y,
|
||
},
|
||
rules: {
|
||
...jsx11y.flatConfigs.recommended.rules,
|
||
'jsx-a11y/no-autofocus': 'warn',
|
||
'jsx-a11y/aria-role': 'error',
|
||
'jsx-a11y/aria-props': 'error',
|
||
'jsx-a11y/aria-proptypes': 'error',
|
||
'jsx-a11y/aria-unsupported-elements': 'error',
|
||
'jsx-a11y/role-has-required-aria-props': 'error',
|
||
'jsx-a11y/role-supports-aria-props': 'error',
|
||
'jsx-a11y/tabindex-no-positive': 'error',
|
||
'jsx-a11y/no-noninteractive-tabindex': 'warn',
|
||
},
|
||
},
|
||
|
||
// React/JSX 文件配置
|
||
{
|
||
files: ['**/*.tsx', '**/*.ts'],
|
||
languageOptions: {
|
||
ecmaVersion: 2024,
|
||
sourceType: 'module',
|
||
parserOptions: {
|
||
ecmaFeatures: { jsx: true },
|
||
},
|
||
},
|
||
rules: {
|
||
// 禁止 any(未知类型用 unknown)
|
||
'@typescript-eslint/no-explicit-any': 'warn',
|
||
// 未使用变量允许下划线前缀
|
||
'@typescript-eslint/no-unused-vars': [
|
||
'error',
|
||
{
|
||
argsIgnorePattern: '^_',
|
||
varsIgnorePattern: '^_',
|
||
},
|
||
],
|
||
// 允许 console(开发环境)
|
||
'no-console': 'off',
|
||
// 允许未定义的 require(Next.js 配置)
|
||
'@typescript-eslint/no-require-imports': 'off',
|
||
},
|
||
},
|
||
|
||
// 测试文件放宽规则
|
||
{
|
||
files: ['**/*.test.ts', '**/*.test.tsx', '**/*.spec.ts'],
|
||
rules: {
|
||
'@typescript-eslint/no-explicit-any': 'off',
|
||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||
'jsx-a11y/no-autofocus': 'off',
|
||
},
|
||
},
|
||
|
||
// 禁用与 Prettier 冲突的规则
|
||
prettierConfig,
|
||
);
|