From 1a29762c4f966a96a234c84079863336a209d71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 1 Sep 2022 17:26:39 +0200 Subject: [PATCH 1/4] detect ESLint config in package.json --- packages/next/lib/eslint/hasEslintConfiguration.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/next/lib/eslint/hasEslintConfiguration.ts b/packages/next/lib/eslint/hasEslintConfiguration.ts index 113e72926192..b0bc7f75f56d 100644 --- a/packages/next/lib/eslint/hasEslintConfiguration.ts +++ b/packages/next/lib/eslint/hasEslintConfiguration.ts @@ -33,12 +33,10 @@ export async function hasEslintConfiguration( } return { ...configObject, exists: true } } else if (packageJsonConfig?.eslintConfig) { - if (Object.entries(packageJsonConfig?.eslintConfig).length === 0) { - return { - ...configObject, - emptyPkgJsonConfig: true, - } + if (Object.keys(packageJsonConfig?.eslintConfig).length) { + return { ...configObject, emptyPkgJsonConfig: true } } + return { ...configObject, exists: true } } return configObject } From 957a135d2a31193191740b1a4f18f31bbe51f7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 1 Sep 2022 17:29:36 +0200 Subject: [PATCH 2/4] swap logic --- packages/next/lib/eslint/hasEslintConfiguration.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/lib/eslint/hasEslintConfiguration.ts b/packages/next/lib/eslint/hasEslintConfiguration.ts index b0bc7f75f56d..6c600f545478 100644 --- a/packages/next/lib/eslint/hasEslintConfiguration.ts +++ b/packages/next/lib/eslint/hasEslintConfiguration.ts @@ -34,9 +34,9 @@ export async function hasEslintConfiguration( return { ...configObject, exists: true } } else if (packageJsonConfig?.eslintConfig) { if (Object.keys(packageJsonConfig?.eslintConfig).length) { - return { ...configObject, emptyPkgJsonConfig: true } + return { ...configObject, exists: true } } - return { ...configObject, exists: true } + return { ...configObject, emptyPkgJsonConfig: true } } return configObject } From 49d3c35cd322ab53ab59f445681246be115b6268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 1 Sep 2022 17:53:22 +0200 Subject: [PATCH 3/4] add test --- .../index.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts b/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts index d24e7755b4ed..788b67f171d7 100644 --- a/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts +++ b/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts @@ -65,5 +65,25 @@ describe('no-eslint-warn-with-no-eslint-config', () => { await next.patchFile('package.json', origPkgJson) } }) + + it('should not warn with eslint config in package.json', async () => { + await next.stop() + const origPkgJson = await next.readFile('package.json') + const pkgJson = JSON.parse(origPkgJson) + pkgJson.eslintConfig = { rules: { semi: 'off' } } + + try { + await next.patchFile('package.json', JSON.stringify(pkgJson)) + await next.start() + + console.log(next.cliOutput) + + expect(next.cliOutput).not.toContain( + 'No ESLint configuration detected. Run next lint to begin setup' + ) + } finally { + await next.patchFile('package.json', origPkgJson) + } + }) } }) From 0bcb6d62b8b15a321d2a32b62d75d9cc31a8ce59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 1 Sep 2022 17:53:54 +0200 Subject: [PATCH 4/4] remove `console.log` --- test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts b/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts index 788b67f171d7..ab31e1f3100b 100644 --- a/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts +++ b/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts @@ -76,8 +76,6 @@ describe('no-eslint-warn-with-no-eslint-config', () => { await next.patchFile('package.json', JSON.stringify(pkgJson)) await next.start() - console.log(next.cliOutput) - expect(next.cliOutput).not.toContain( 'No ESLint configuration detected. Run next lint to begin setup' )