forked from cardosofelipe/fast-next-template
Update to Next.js 16 and enhance ESLint configuration
- Migrated from Next.js 15 to Next.js 16, updating all related dependencies and configurations. - Enhanced ESLint setup with stricter rules, expanded plugin support, and improved type-aware linting options. - Archived middleware by renaming it to `middleware.disabled.ts` for potential future use.
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
import { FlatCompat } from '@eslint/eslintrc';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import nextPlugin from '@next/eslint-plugin-next';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import reactPlugin from 'eslint-plugin-react';
|
||||
import reactHooks from 'eslint-plugin-react-hooks';
|
||||
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const nextCoreWebVitalsRules = nextPlugin.configs['core-web-vitals']?.rules ?? {};
|
||||
|
||||
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
|
||||
export default [
|
||||
// Ignores
|
||||
{
|
||||
ignores: [
|
||||
'node_modules/**',
|
||||
@@ -25,8 +20,43 @@ const eslintConfig = [
|
||||
'*.gen.ts',
|
||||
'*.gen.tsx',
|
||||
'next-env.d.ts', // Auto-generated by Next.js
|
||||
'eslint.config.mjs', // Do not lint the ESLint config itself
|
||||
],
|
||||
},
|
||||
|
||||
// TypeScript recommended (non-type-checked) rules for broader compatibility
|
||||
...tseslint.configs.recommended,
|
||||
|
||||
// If you want type-aware linting, uncomment below and switch to `recommendedTypeChecked`
|
||||
// {
|
||||
// files: ['**/*.{ts,tsx}'],
|
||||
// languageOptions: {
|
||||
// parserOptions: {
|
||||
// project: ['./tsconfig.json'],
|
||||
// tsconfigRootDir: new URL('.', import.meta.url).pathname,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
|
||||
// Next.js + React rules (Core Web Vitals)
|
||||
{
|
||||
files: ['**/*.{js,jsx,ts,tsx}'],
|
||||
plugins: {
|
||||
'@next/next': nextPlugin,
|
||||
react: reactPlugin,
|
||||
'react-hooks': reactHooks,
|
||||
'jsx-a11y': jsxA11y,
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...nextCoreWebVitalsRules,
|
||||
},
|
||||
},
|
||||
|
||||
// Base rules for source code
|
||||
{
|
||||
files: ['src/**/*.{ts,tsx}'],
|
||||
@@ -50,6 +80,7 @@ const eslintConfig = [
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// Relaxed rules for test files
|
||||
{
|
||||
files: ['tests/**/*.{ts,tsx}', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'],
|
||||
@@ -68,6 +99,7 @@ const eslintConfig = [
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// Relaxed rules for E2E tests
|
||||
{
|
||||
files: ['e2e/**/*.{ts,tsx}'],
|
||||
@@ -83,6 +115,7 @@ const eslintConfig = [
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// Relaxed rules for scripts and config files
|
||||
{
|
||||
files: ['scripts/**/*.{ts,js}', '*.config.{ts,js,mjs}', 'jest.setup.js'],
|
||||
@@ -101,5 +134,3 @@ const eslintConfig = [
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default eslintConfig;
|
||||
|
||||
Reference in New Issue
Block a user