forked from cardosofelipe/fast-next-template
- Added `eslint-config-prettier` to disable conflicting ESLint rules. - Configured Prettier with `.prettierrc` for consistent formatting. - Updated `package.json` scripts to apply and check formatting on entire project. - Added `.prettierignore` to exclude unnecessary files and directories from formatting. - Updated dependencies in `package-lock.json` and removed unused packages.
106 lines
3.2 KiB
JavaScript
Executable File
106 lines
3.2 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'),
|
|
...compat.extends('prettier'), // Disable ESLint rules that conflict with Prettier
|
|
{
|
|
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;
|