Unverified Commit b8562839 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Remove eslint warning when no eslint config is present (#39872)

We shouldn't be warning when no eslint config file is present as it's valid not to use eslint. The warning is still shown if an empty eslint config file is added as this gives intent to using eslint. 

x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1661268593890619?thread_ts=1661266342.496699&cid=CGU8HUTUH)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent 7f5bc717
......@@ -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 {
......@@ -38,9 +39,6 @@ export async function hasEslintConfiguration(
emptyPkgJsonConfig: true,
}
}
} else {
return configObject
}
return { ...configObject, exists: true }
return configObject
}
......@@ -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'
......
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)
}
})
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment