Skip to content

Commit 37f6977

Browse files
committed
feat(eslint-config): unify react function component style
1 parent ecee627 commit 37f6977

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

packages/eslint-config/src/nextjs/config.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,19 @@ export const config = (apps = ['.']): Linter.Config[] => [
2222
},
2323
},
2424
{
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-
],
35-
},
36-
},
37-
{
38-
files: apps.map((app) => [`${app}/app/**/layout.tsx`, `${app}/src/**/layouts/**/*.tsx`]).flat(),
25+
files: apps.map((app) => [`${app}/src/**/layout.tsx`, `${app}/src/**/layouts/**/*.tsx`]).flat(),
3926
rules: {
4027
'@next/next/no-head-element': 'off', // Allow <head/> element in Next.js App layouts
4128
},
4229
},
4330
{
4431
files: apps
45-
.map((app) => [`${app}/src/**/layouts/**/*.tsx`, `${app}/src/pages/_app.tsx`, `${app}/src/pages/_document.tsx`])
32+
.map((app) => [
33+
`${app}/src/**/layout.tsx`,
34+
`${app}/src/**/layouts/**/*.tsx`,
35+
`${app}/src/pages/_app.tsx`,
36+
`${app}/src/pages/_document.tsx`,
37+
])
4638
.flat(),
4739
rules: {
4840
'react/jsx-props-no-spreading': 'off', // Allow spreading props in Next.js App layouts, _app.tsx and _document.tsx

packages/eslint-config/src/react/rules/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const common: Linter.RulesRecord = {
55
// Prefer arrow functions for React components and avoid unnamed components with function expressions
66
'error',
77
{
8-
namedComponents: ['arrow-function'],
8+
namedComponents: ['arrow-function', 'function-declaration'],
99
unnamedComponents: 'function-expression',
1010
},
1111
],

0 commit comments

Comments
 (0)