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`).
This commit is contained in:
@@ -9,7 +9,7 @@ const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
});
|
||||
|
||||
export default [
|
||||
const eslintConfig = [
|
||||
...compat.extends('next/core-web-vitals'),
|
||||
...compat.extends('next/typescript'),
|
||||
{
|
||||
@@ -23,9 +23,12 @@ export default [
|
||||
'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
|
||||
@@ -46,4 +49,56 @@ export default [
|
||||
],
|
||||
},
|
||||
},
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user