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

Improve check for eslint version #25910

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/next/lib/eslint/runLintCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as CommentJson from 'next/dist/compiled/comment-json'

import { formatResults } from './customFormatter'
import { writeDefaultConfig } from './writeDefaultConfig'
import { getPackageVersion } from '../get-package-version'
import { findPagesDir } from '../find-pages-dir'

import { CompileError } from '../compile-error'
Expand Down Expand Up @@ -35,19 +34,25 @@ async function lint(
pkgJsonPath: string | null
): Promise<string | null> {
// Load ESLint after we're sure it exists:
const { ESLint } = await import(deps.resolved)
const mod = await import(deps.resolved)

const { ESLint } = mod

if (!ESLint) {
const eslintVersion: string | null = await getPackageVersion({
cwd: baseDir,
name: 'eslint',
})
const eslintVersion: string | undefined = mod?.CLIEngine?.version

if (eslintVersion && semver.lt(eslintVersion, '7.0.0')) {
if (!eslintVersion || semver.lt(eslintVersion, '7.0.0')) {
Log.error(
`Your project has an older version of ESLint installed (${eslintVersion}). Please upgrade to v7 or later`
`Your project has an older version of ESLint installed${
eslintVersion ? ' (' + eslintVersion + ')' : ''
}. Please upgrade to ESLint version 7 or later`
)
return null
}

Log.error(
`ESLint class not found. Please upgrade to ESLint version 7 or later`
)
return null
}

Expand Down