|
1 | 1 | import { FlatCompat } from '@eslint/eslintrc'; |
| 2 | +import type { Linter } from 'eslint'; |
2 | 3 |
|
3 | 4 | const compat = new FlatCompat({ |
4 | 5 | baseDirectory: import.meta.dirname, |
5 | 6 | }); |
6 | 7 |
|
7 | | -export const [config] = compat.config({ |
8 | | - extends: ['plugin:@next/next/recommended'], |
9 | | - plugins: ['@next/next'], |
10 | | - settings: { |
11 | | - next: { |
12 | | - rootDir: process.cwd(), |
13 | | - }, |
14 | | - }, |
15 | | - overrides: [ |
16 | | - { |
17 | | - files: ['next-env.d.ts'], |
18 | | - rules: { |
19 | | - 'unicorn/prevent-abbreviations': 'off', // next-env.d.ts is a Next.js convention |
| 8 | +export const config = (apps = ['.']): Linter.Config[] => [ |
| 9 | + ...compat.config({ |
| 10 | + extends: ['plugin:@next/next/recommended'], |
| 11 | + plugins: ['@next/next'], |
| 12 | + settings: { |
| 13 | + next: { |
| 14 | + rootDir: process.cwd(), |
20 | 15 | }, |
21 | 16 | }, |
22 | | - { |
23 | | - files: ['src/app/**/*.ts', 'src/app/**/*.tsx', 'src/pages/**/*.ts', 'src/pages/**/*.tsx'], |
24 | | - rules: { |
25 | | - 'react/function-component-definition': [ |
26 | | - // Allow components as function declarations in Next.js App and Page components for shorthand default exports |
27 | | - 'error', |
28 | | - { |
29 | | - namedComponents: ['arrow-function', 'function-declaration'], |
30 | | - unnamedComponents: 'function-expression', |
31 | | - }, |
32 | | - ], |
33 | | - }, |
| 17 | + }), |
| 18 | + { |
| 19 | + files: apps.map((app) => `${app}/next-env.d.ts`), |
| 20 | + rules: { |
| 21 | + 'unicorn/prevent-abbreviations': 'off', // next-env.d.ts is a Next.js convention |
34 | 22 | }, |
35 | | - { |
36 | | - files: ['app/**/layout.tsx', 'src/**/layouts/**/*.tsx'], |
37 | | - rules: { |
38 | | - '@next/next/no-head-element': 'off', // Allow <head/> element in Next.js App layouts |
39 | | - }, |
| 23 | + }, |
| 24 | + { |
| 25 | + files: apps.map((app) => [`${app}/src/app/**/*.{ts,tsx}`, `${app}/src/pages/**/*.{ts,tsx}`]).flat(), |
| 26 | + rules: { |
| 27 | + 'react/function-component-definition': [ |
| 28 | + // Allow components as function declarations in Next.js App and Page components for shorthand default exports |
| 29 | + 'error', |
| 30 | + { |
| 31 | + namedComponents: ['arrow-function', 'function-declaration'], |
| 32 | + unnamedComponents: 'function-expression', |
| 33 | + }, |
| 34 | + ], |
40 | 35 | }, |
41 | | - { |
42 | | - files: ['src/**/layouts/**/*.tsx', 'rc/pages/_app.tsx', 'src/pages/_document.tsx'], |
43 | | - rules: { |
44 | | - 'react/jsx-props-no-spreading': 'off', // Allow spreading props in Next.js App layouts, _app.tsx and _document.tsx |
45 | | - }, |
| 36 | + }, |
| 37 | + { |
| 38 | + files: apps.map((app) => [`${app}/app/**/layout.tsx`, `${app}/src/**/layouts/**/*.tsx`]).flat(), |
| 39 | + rules: { |
| 40 | + '@next/next/no-head-element': 'off', // Allow <head/> element in Next.js App layouts |
46 | 41 | }, |
47 | | - { |
48 | | - files: ['src/**/actions.ts'], |
49 | | - rules: { |
50 | | - '@typescript-eslint/require-await': 'off', // Next.js Server Actions must be async but don't need to await |
51 | | - }, |
| 42 | + }, |
| 43 | + { |
| 44 | + files: apps |
| 45 | + .map((app) => [`${app}/src/**/layouts/**/*.tsx`, `${app}/src/pages/_app.tsx`, `${app}/src/pages/_document.tsx`]) |
| 46 | + .flat(), |
| 47 | + rules: { |
| 48 | + 'react/jsx-props-no-spreading': 'off', // Allow spreading props in Next.js App layouts, _app.tsx and _document.tsx |
52 | 49 | }, |
53 | | - ], |
54 | | -}); |
| 50 | + }, |
| 51 | + { |
| 52 | + files: apps.map((app) => `${app}/src/**/actions.ts`), |
| 53 | + rules: { |
| 54 | + '@typescript-eslint/require-await': 'off', // Next.js Server Actions must be async but don't need to await |
| 55 | + }, |
| 56 | + }, |
| 57 | +]; |
0 commit comments