From 2de7b43b7819b4148f019ec560651e54e9ba562c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 1 Sep 2022 17:23:03 +0100 Subject: [PATCH] fix: detect ESLint config in package.json (#40158) Fixes #40133 Fixes a small regression introduced in #39872. We should be able to detect if a non-empty `package.json#eslintConfig` property is present. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) --- .../next/lib/eslint/hasEslintConfiguration.ts | 8 +++----- .../index.test.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) 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) + } + }) } })