| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import js from '@eslint/js';
- import typescriptEslint from '@typescript-eslint/eslint-plugin';
- import typescriptParser from '@typescript-eslint/parser';
- import globals from 'globals';
- /**
- * ESLint 配置 for @d8d/e2e-test-utils
- *
- * 此配置捕获常见代码问题,包括:
- * - 冗余的 null 检查
- * - 未使用的变量
- * - 空 catch 块
- * - 首选 const 而非 let
- *
- * 参见: _bmad-output/implementation-artifacts/epic-1-retrospective.md
- */
- /** @type {import('eslint').Linter.Config[]} */
- const config = [
- // 基础配置
- {
- files: ['**/*.{js,ts}'],
- ignores: [
- 'dist/**',
- 'node_modules/**',
- '*.config.js',
- '*.config.ts',
- 'coverage/**',
- ],
- languageOptions: {
- ecmaVersion: 'latest',
- sourceType: 'module',
- parser: typescriptParser,
- parserOptions: {
- project: './tsconfig.json',
- },
- globals: {
- ...globals.node,
- ...globals.es2021,
- },
- },
- plugins: {
- '@typescript-eslint': typescriptEslint,
- },
- rules: {
- // 基础 ESLint 规则
- ...js.configs.recommended.rules,
- // TypeScript 规则
- '@typescript-eslint/no-unused-vars': ['error', {
- argsIgnorePattern: '^_',
- varsIgnorePattern: '^_',
- caughtErrorsIgnorePattern: '^_',
- }],
- '@typescript-eslint/no-explicit-any': 'error',
- '@typescript-eslint/explicit-function-return-type': 'off',
- '@typescript-eslint/no-non-null-assertion': 'warn',
- // 捕获冗余的 null 检查 (来自 Epic 1 回顾)
- 'no-constant-binary-expression': 'error',
- // 捕获空 catch 块 (来自 Epic 1 回顾)
- 'no-empty': ['error', { allowEmptyCatch: false }],
- // 首选 const (来自 Epic 1 回顾)
- 'prefer-const': 'error',
- // 其他有用的规则
- 'no-console': 'off', // 测试工具可能需要 console.debug
- 'no-undef': 'off', // TypeScript 已经处理了未定义变量
- 'no-unused-vars': 'off', // 使用 TypeScript 的版本
- },
- },
- // 测试环境配置 (Vitest)
- {
- files: ['tests/**/*.test.ts', 'tests/**/*.spec.ts'],
- languageOptions: {
- globals: {
- ...globals.node,
- ...vitestGlobals,
- },
- },
- },
- ];
- // Vitest 全局变量
- const vitestGlobals = {
- describe: 'readonly',
- it: 'readonly',
- test: 'readonly',
- expect: 'readonly',
- beforeEach: 'readonly',
- afterEach: 'readonly',
- beforeAll: 'readonly',
- afterAll: 'readonly',
- vi: 'readonly',
- };
- export default config;
|