Skip to content

Commit 4c53843

Browse files
devjiwonchoiijjk
andauthored
fix(next-eslint): .eslintrc.json not being created by next lint on App Router (vercel#55104)
This PR fixes `.eslintrc.json` not being created after the user runs `next lint` and selects an option of `Strict` or `Base`. The reason is that the lint check was looking for `pages` and `src/pages` only. Added `app` and `src/app` to be checked also. Fixes: vercel#55094 Fixes: vercel#55102 --------- Co-authored-by: JJ Kasper <[email protected]>
1 parent 4ba1f06 commit 4c53843

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

packages/next/src/lib/eslint/runLintCheck.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ export async function runLintCheck(
375375
// Write default ESLint config.
376376
// Check for /pages and src/pages is to make sure this happens in Next.js folder
377377
if (
378-
existsSync(path.join(baseDir, 'pages')) ||
379-
existsSync(path.join(baseDir, 'src/pages'))
378+
['app', 'src/app', 'pages', 'src/pages'].some((dir) =>
379+
existsSync(path.join(baseDir, dir))
380+
)
380381
) {
381382
await writeDefaultConfig(
382383
baseDir,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function RootLayout({ children }) {
2+
return (
3+
<html lang="en">
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Home() {
2+
return (
3+
<div>
4+
<h1>Hello World!</h1>
5+
</div>
6+
)
7+
}

test/integration/eslint/test/next-lint.test.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ const dirTypescript = join(__dirname, '../with-typescript')
3838

3939
describe('Next Lint', () => {
4040
describe('First Time Setup ', () => {
41-
async function nextLintTemp(setupCallback) {
41+
async function nextLintTemp(setupCallback, isApp = false) {
4242
const folder = join(os.tmpdir(), Math.random().toString(36).substring(2))
4343
await fs.mkdirp(folder)
44-
await fs.copy(dirNoConfig, folder)
44+
await fs.copy(join(dirNoConfig, isApp ? 'app' : ''), folder)
4545
await setupCallback?.(folder)
4646

4747
try {
@@ -101,6 +101,23 @@ describe('Next Lint', () => {
101101
expect(stdout).toContain(packageManger)
102102
expect(pkgJson.devDependencies).toHaveProperty('eslint')
103103
expect(pkgJson.devDependencies).toHaveProperty('eslint-config-next')
104+
105+
// App Router
106+
const { stdout: appStdout, pkgJson: appPkgJson } = await nextLintTemp(
107+
async (folder) => {
108+
await fs.writeFile(join(folder, lockFile), '')
109+
},
110+
true
111+
)
112+
113+
expect(appStdout).toContain(
114+
`Installing devDependencies (${packageManger}):`
115+
)
116+
expect(appStdout).toContain('eslint')
117+
expect(appStdout).toContain('eslint-config-next')
118+
expect(appStdout).toContain(packageManger)
119+
expect(appPkgJson.devDependencies).toHaveProperty('eslint')
120+
expect(appPkgJson.devDependencies).toHaveProperty('eslint-config-next')
104121
})
105122
}
106123

@@ -111,6 +128,15 @@ describe('Next Lint', () => {
111128
'We created the .eslintrc.json file for you and included your selected configuration'
112129
)
113130
expect(eslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
131+
132+
// App Router
133+
const { stdout: appStdout, eslintrcJson: appEslintrcJson } =
134+
await nextLintTemp(null, true)
135+
136+
expect(appStdout).toContain(
137+
'We created the .eslintrc.json file for you and included your selected configuration'
138+
)
139+
expect(appEslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
114140
})
115141

116142
test('shows a successful message when completed', async () => {
@@ -119,6 +145,12 @@ describe('Next Lint', () => {
119145
expect(stdout).toContain(
120146
'ESLint has successfully been configured. Run next lint again to view warnings and errors'
121147
)
148+
149+
// App Router
150+
const { stdout: appStdout } = await nextLintTemp(null, true)
151+
expect(appStdout).toContain(
152+
'ESLint has successfully been configured. Run next lint again to view warnings and errors'
153+
)
122154
})
123155
})
124156

0 commit comments

Comments
 (0)