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

Remove eslint warning when no eslint config is present #39872

Merged
merged 3 commits into from Aug 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/next/lib/eslint/hasEslintConfiguration.ts
Expand Up @@ -31,16 +31,14 @@ export async function hasEslintConfiguration(
) {
return { ...configObject, emptyEslintrc: true }
}
return { ...configObject, exists: true }
} else if (packageJsonConfig?.eslintConfig) {
if (Object.entries(packageJsonConfig?.eslintConfig).length === 0) {
return {
...configObject,
emptyPkgJsonConfig: true,
}
}
} else {
return configObject
}

return { ...configObject, exists: true }
return configObject
}
9 changes: 7 additions & 2 deletions packages/next/lib/eslint/runLintCheck.ts
Expand Up @@ -321,8 +321,13 @@ export async function runLintCheck(
outputFile
)
} else {
// Display warning if no ESLint configuration is present during "next build"
if (lintDuringBuild) {
// 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 &&
(config.emptyPkgJsonConfig || config.emptyEslintrc)
) {
Log.warn(
`No ESLint configuration detected. Run ${chalk.bold.cyan(
'next lint'
Expand Down
69 changes: 69 additions & 0 deletions test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts
@@ -0,0 +1,69 @@
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

if ((global as any).isNextDeploy) {
it('should skip for deploy', () => {})
return
}

beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
},
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')
})

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)
}
})
}
})