diff --git a/packages/next/src/lib/eslint/runLintCheck.ts b/packages/next/src/lib/eslint/runLintCheck.ts
index 525dbb24f2893..9e2d2967b1808 100644
--- a/packages/next/src/lib/eslint/runLintCheck.ts
+++ b/packages/next/src/lib/eslint/runLintCheck.ts
@@ -375,8 +375,9 @@ export async function runLintCheck(
// Write default ESLint config.
// Check for /pages and src/pages is to make sure this happens in Next.js folder
if (
- existsSync(path.join(baseDir, 'pages')) ||
- existsSync(path.join(baseDir, 'src/pages'))
+ ['app', 'src/app', 'pages', 'src/pages'].some((dir) =>
+ existsSync(path.join(baseDir, dir))
+ )
) {
await writeDefaultConfig(
baseDir,
diff --git a/test/integration/eslint/no-config/app/app/layout.js b/test/integration/eslint/no-config/app/app/layout.js
new file mode 100644
index 0000000000000..4ee00a218505a
--- /dev/null
+++ b/test/integration/eslint/no-config/app/app/layout.js
@@ -0,0 +1,7 @@
+export default function RootLayout({ children }) {
+ return (
+
+
{children}
+
+ )
+}
diff --git a/test/integration/eslint/no-config/app/app/page.js b/test/integration/eslint/no-config/app/app/page.js
new file mode 100644
index 0000000000000..95b74830f62e1
--- /dev/null
+++ b/test/integration/eslint/no-config/app/app/page.js
@@ -0,0 +1,7 @@
+export default function Home() {
+ return (
+
+
Hello World!
+
+ )
+}
diff --git a/test/integration/eslint/test/next-lint.test.js b/test/integration/eslint/test/next-lint.test.js
index 1fd6ca6399ab0..acc97e6f93c9e 100644
--- a/test/integration/eslint/test/next-lint.test.js
+++ b/test/integration/eslint/test/next-lint.test.js
@@ -38,10 +38,10 @@ const dirTypescript = join(__dirname, '../with-typescript')
describe('Next Lint', () => {
describe('First Time Setup ', () => {
- async function nextLintTemp(setupCallback) {
+ async function nextLintTemp(setupCallback, isApp = false) {
const folder = join(os.tmpdir(), Math.random().toString(36).substring(2))
await fs.mkdirp(folder)
- await fs.copy(dirNoConfig, folder)
+ await fs.copy(join(dirNoConfig, isApp ? 'app' : ''), folder)
await setupCallback?.(folder)
try {
@@ -101,6 +101,23 @@ describe('Next Lint', () => {
expect(stdout).toContain(packageManger)
expect(pkgJson.devDependencies).toHaveProperty('eslint')
expect(pkgJson.devDependencies).toHaveProperty('eslint-config-next')
+
+ // App Router
+ const { stdout: appStdout, pkgJson: appPkgJson } = await nextLintTemp(
+ async (folder) => {
+ await fs.writeFile(join(folder, lockFile), '')
+ },
+ true
+ )
+
+ expect(appStdout).toContain(
+ `Installing devDependencies (${packageManger}):`
+ )
+ expect(appStdout).toContain('eslint')
+ expect(appStdout).toContain('eslint-config-next')
+ expect(appStdout).toContain(packageManger)
+ expect(appPkgJson.devDependencies).toHaveProperty('eslint')
+ expect(appPkgJson.devDependencies).toHaveProperty('eslint-config-next')
})
}
@@ -111,6 +128,15 @@ describe('Next Lint', () => {
'We created the .eslintrc.json file for you and included your selected configuration'
)
expect(eslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
+
+ // App Router
+ const { stdout: appStdout, eslintrcJson: appEslintrcJson } =
+ await nextLintTemp(null, true)
+
+ expect(appStdout).toContain(
+ 'We created the .eslintrc.json file for you and included your selected configuration'
+ )
+ expect(appEslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
})
test('shows a successful message when completed', async () => {
@@ -119,6 +145,12 @@ describe('Next Lint', () => {
expect(stdout).toContain(
'ESLint has successfully been configured. Run next lint again to view warnings and errors'
)
+
+ // App Router
+ const { stdout: appStdout } = await nextLintTemp(null, true)
+ expect(appStdout).toContain(
+ 'ESLint has successfully been configured. Run next lint again to view warnings and errors'
+ )
})
})