Files
syndarix/frontend/eslint.config.mjs
Felipe Cardoso b2f3ec8f25 Refactor ESLint configuration and update test rules for clarity and consistency
- Consolidated and modularized `eslint.config.mjs` with defined rules for source, test, E2E, and scripts.
- Improved test and E2E rules with relaxed settings for flexibility and enhanced mocking.
- Standardized variable naming and removed redundant imports in unit and E2E tests.
- Updated error handling and comments to align with modern TypeScript best practices (e.g., `@ts-expect-error`).
2025-11-10 10:57:43 +01:00

105 lines
3.1 KiB
JavaScript
Executable File

import { FlatCompat } from '@eslint/eslintrc';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.extends('next/core-web-vitals'),
...compat.extends('next/typescript'),
{
ignores: [
'node_modules/**',
'.next/**',
'out/**',
'build/**',
'dist/**',
'coverage/**',
'src/lib/api/generated/**',
'*.gen.ts',
'*.gen.tsx',
'next-env.d.ts', // Auto-generated by Next.js
],
},
// Base rules for source code
{
files: ['src/**/*.{ts,tsx}'],
rules: {
// Enforce Dependency Injection pattern for auth store
// Components/hooks must use useAuth() from AuthContext, not useAuthStore directly
// This ensures testability via DI (E2E mocks, unit test props)
// Exception: Non-React contexts (client.ts) use dynamic import + __TEST_AUTH_STORE__ check
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/stores/authStore'],
importNames: ['useAuthStore'],
message:
"Import useAuth from '@/lib/auth/AuthContext' instead. Direct authStore imports bypass dependency injection and break test mocking.",
},
],
},
],
},
},
// Relaxed rules for test files
{
files: ['tests/**/*.{ts,tsx}', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off', // Test mocks often need any
'@typescript-eslint/no-require-imports': 'off', // Jest sometimes needs require
'react/display-name': 'off', // Mock components don't need display names
'no-restricted-imports': 'off', // Tests can import store directly
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
},
},
// Relaxed rules for E2E tests
{
files: ['e2e/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off', // Playwright helpers need flexibility
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
},
},
// Relaxed rules for scripts and config files
{
files: ['scripts/**/*.{ts,js}', '*.config.{ts,js,mjs}', 'jest.setup.js'],
rules: {
'@typescript-eslint/no-explicit-any': 'off', // Build scripts need flexibility
'@typescript-eslint/no-require-imports': 'off', // CommonJS configs
'@next/next/no-assign-module-variable': 'off', // Scripts may need module.exports
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
},
},
];
export default eslintConfig;