Skip to content

Commit

Permalink
Improve check for eslint version (#25910)
Browse files Browse the repository at this point in the history
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
timneutkens and ijjk committed Jun 8, 2021
1 parent d2caaea commit c862409
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit c862409

Please sign in to comment.