import { dirname } from 'path'; import { fileURLToPath } from 'url'; import nextConfig from 'eslint-config-next'; import tsParser from '@typescript-eslint/parser'; import tsPlugin from '@typescript-eslint/eslint-plugin'; import reactPlugin from 'eslint-plugin-react'; import reactHooksPlugin from 'eslint-plugin-react-hooks'; const __dirname = dirname(fileURLToPath(import.meta.url)); const config = [ ...nextConfig, { name: 'ruixin/custom', files: ['**/*.{js,jsx,ts,tsx}'], languageOptions: { parser: tsParser, parserOptions: { ecmaVersion: 2020, sourceType: 'module', ecmaFeatures: { jsx: true, }, }, globals: { jest: 'readonly', }, }, plugins: { '@typescript-eslint': tsPlugin, react: reactPlugin, 'react-hooks': reactHooksPlugin, }, settings: { react: { version: 'detect', }, }, rules: { 'react/react-in-jsx-scope': 'off', 'react/no-unescaped-entities': 'error', 'react/jsx-no-target-blank': 'error', 'react/self-closing-comp': 'error', 'react/display-name': 'off', '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', }, ], '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-empty-object-type': 'off', 'no-console': ['warn', { allow: ['warn', 'error'] }], 'prefer-const': 'error', 'no-var': 'error', eqeqeq: ['error', 'always'], curly: ['error', 'multi-line'], 'no-throw-literal': 'error', 'prefer-promise-reject-errors': 'error', 'react-hooks/set-state-in-effect': 'warn', }, }, { name: 'ruixin/e2e-tests', files: ['e2e/**/*.ts'], rules: { // E2E 测试使用 console.log 输出诊断信息,允许 'no-console': 'off', }, }, { name: 'ruixin/unit-tests', files: ['**/*.test.{ts,tsx}', '**/__tests__/**/*.{ts,tsx}'], rules: { // 单测/集成测试在 mock 与断言中常使用 any,允许 '@typescript-eslint/no-explicit-any': 'off', }, }, { name: 'ruixin/performance-tests', files: ['tests/performance/*.js'], rules: { // k6 性能测试脚本按惯例使用匿名默认导出 'import/no-anonymous-default-export': 'off', }, }, { name: 'ruixin/ignores', ignores: [ '.next/**', 'out/**', 'build/**', 'dist/**', 'node_modules/**', 'coverage/**', 'scripts/**', 'config/test/**', '**/_archive/**', '.agents/**', 'test-framework/**', 'tests/styles/**', 'next-env.d.ts', 'playwright-report/**', '.lighthouseci/**', 'test-results/**', 'release-acceptance-reports/**', '.trae/**', '*.log', '*.txt', 'build-output.txt', 'e2e-output.txt', 'type-check-output.txt', 'lint-output.txt', 'npm-audit-output.txt', 'test-unit-output.txt', 'accessibility-report.json', 'heading-hierarchy-report.json', ], }, ]; export default config;