From 8d17b1b67244150a2739ebe870fad5d3e95e244b Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 23 Aug 2022 10:44:53 -0500 Subject: [PATCH 1/3] Remove eslint warning when no eslint config is present --- packages/next/lib/eslint/runLintCheck.ts | 16 +++++---- .../index.test.ts | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts diff --git a/packages/next/lib/eslint/runLintCheck.ts b/packages/next/lib/eslint/runLintCheck.ts index 3e3a46af5e681..bedbc52744713 100644 --- a/packages/next/lib/eslint/runLintCheck.ts +++ b/packages/next/lib/eslint/runLintCheck.ts @@ -321,13 +321,17 @@ export async function runLintCheck( outputFile ) } else { - // Display warning if no ESLint configuration is present during "next build" + // Display warning if no ESLint configuration is present inside + // config file during "next build", no warning is shown when + // no eslintrc file is present if (lintDuringBuild) { - Log.warn( - `No ESLint configuration detected. Run ${chalk.bold.cyan( - 'next lint' - )} to begin setup` - ) + if (eslintrcFile) { + Log.warn( + `No ESLint configuration detected. Run ${chalk.bold.cyan( + 'next lint' + )} to begin setup` + ) + } return null } else { // Ask user what config they would like to start with for first time "next lint" setup 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 new file mode 100644 index 0000000000000..9fc2e19ed7c3b --- /dev/null +++ b/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts @@ -0,0 +1,33 @@ +import { createNext } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { renderViaHTTP } from 'next-test-utils' + +describe('no-eslint-warn-with-no-eslint-config', () => { + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: { + 'pages/index.js': ` + export default function Page() { + return

hello world

+ } + `, + }, + dependencies: {}, + }) + }) + afterAll(() => next.destroy()) + + it('should render', async () => { + const html = await renderViaHTTP(next.url, '/') + expect(html).toContain('hello world') + }) + + it('should not have eslint warnings when no eslint config', async () => { + expect(next.cliOutput).not.toContain( + 'No ESLint configuration detected. Run next lint to begin setup' + ) + expect(next.cliOutput).not.toBe('warn') + }) +}) From 775b6477ccadc2f83575c813e578946fa932d7d2 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 23 Aug 2022 12:03:51 -0500 Subject: [PATCH 2/3] update check and more tests --- .../next/lib/eslint/hasEslintConfiguration.ts | 5 +-- packages/next/lib/eslint/runLintCheck.ts | 17 ++++----- .../index.test.ts | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/packages/next/lib/eslint/hasEslintConfiguration.ts b/packages/next/lib/eslint/hasEslintConfiguration.ts index 2b3418f7966b1..896fec0882e04 100644 --- a/packages/next/lib/eslint/hasEslintConfiguration.ts +++ b/packages/next/lib/eslint/hasEslintConfiguration.ts @@ -38,9 +38,6 @@ export async function hasEslintConfiguration( emptyPkgJsonConfig: true, } } - } else { - return configObject } - - return { ...configObject, exists: true } + return configObject } diff --git a/packages/next/lib/eslint/runLintCheck.ts b/packages/next/lib/eslint/runLintCheck.ts index bedbc52744713..05c49caeb0278 100644 --- a/packages/next/lib/eslint/runLintCheck.ts +++ b/packages/next/lib/eslint/runLintCheck.ts @@ -324,14 +324,15 @@ export async function runLintCheck( // Display warning if no ESLint configuration is present inside // config file during "next build", no warning is shown when // no eslintrc file is present - if (lintDuringBuild) { - if (eslintrcFile) { - Log.warn( - `No ESLint configuration detected. Run ${chalk.bold.cyan( - 'next lint' - )} to begin setup` - ) - } + if ( + lintDuringBuild && + (config.emptyPkgJsonConfig || config.emptyEslintrc) + ) { + Log.warn( + `No ESLint configuration detected. Run ${chalk.bold.cyan( + 'next lint' + )} to begin setup` + ) return null } else { // Ask user what config they would like to start with for first time "next lint" setup 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 9fc2e19ed7c3b..d24e7755b4ed3 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 @@ -5,6 +5,11 @@ import { renderViaHTTP } from 'next-test-utils' describe('no-eslint-warn-with-no-eslint-config', () => { let next: NextInstance + if ((global as any).isNextDeploy) { + it('should skip for deploy', () => {}) + return + } + beforeAll(async () => { next = await createNext({ files: { @@ -30,4 +35,35 @@ describe('no-eslint-warn-with-no-eslint-config', () => { ) expect(next.cliOutput).not.toBe('warn') }) + + if (!(global as any).isNextDev) { + it('should warn with empty eslintrc', async () => { + await next.stop() + await next.patchFile('.eslintrc.json', '{}') + await next.start() + + expect(next.cliOutput).toContain( + 'No ESLint configuration detected. Run next lint to begin setup' + ) + }) + + it('should warn with empty eslint config in package.json', async () => { + await next.stop() + await next.deleteFile('.eslintrc.json') + const origPkgJson = await next.readFile('package.json') + const pkgJson = JSON.parse(origPkgJson) + pkgJson.eslintConfig = {} + + try { + await next.patchFile('package.json', JSON.stringify(pkgJson)) + await next.start() + + expect(next.cliOutput).toContain( + 'No ESLint configuration detected. Run next lint to begin setup' + ) + } finally { + await next.patchFile('package.json', origPkgJson) + } + }) + } }) From 9798c085894a296831bc07bdb4666e8a5aeee3e5 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 23 Aug 2022 12:24:56 -0500 Subject: [PATCH 3/3] fix --- packages/next/lib/eslint/hasEslintConfiguration.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/next/lib/eslint/hasEslintConfiguration.ts b/packages/next/lib/eslint/hasEslintConfiguration.ts index 896fec0882e04..113e72926192a 100644 --- a/packages/next/lib/eslint/hasEslintConfiguration.ts +++ b/packages/next/lib/eslint/hasEslintConfiguration.ts @@ -31,6 +31,7 @@ export async function hasEslintConfiguration( ) { return { ...configObject, emptyEslintrc: true } } + return { ...configObject, exists: true } } else if (packageJsonConfig?.eslintConfig) { if (Object.entries(packageJsonConfig?.eslintConfig).length === 0) { return {