diff --git a/packages/next/lib/eslint/hasEslintConfiguration.ts b/packages/next/lib/eslint/hasEslintConfiguration.ts index 113e72926192..6c600f545478 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, exists: true } } + return { ...configObject, emptyPkgJsonConfig: true } } return configObject } 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..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 @@ -65,5 +65,23 @@ 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() + + expect(next.cliOutput).not.toContain( + 'No ESLint configuration detected. Run next lint to begin setup' + ) + } finally { + await next.patchFile('package.json', origPkgJson) + } + }) } })