Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(next-eslint): .eslintrc.json not being created by next lint on App Router #55104

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/next/src/lib/eslint/runLintCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions test/integration/eslint/no-config/app/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
7 changes: 7 additions & 0 deletions test/integration/eslint/no-config/app/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<div>
<h1>Hello World!</h1>
</div>
)
}
36 changes: 34 additions & 2 deletions test/integration/eslint/test/next-lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
})
}

Expand All @@ -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 () => {
Expand All @@ -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'
)
})
})

Expand Down