Commit 0a90014c authored by Ben Gubler's avatar Ben Gubler

feat [Next 16]: remove automatic linting from build

parent 8a594ed2
......@@ -344,7 +344,7 @@ npx @next/codemod@canary next-lint-to-eslint-cli .
If you use ESLint, create an explicit config (recommended `eslint.config.mjs`). ESLint supports both [the legacy `.eslintrc.*` and the newer `eslint.config.mjs` formats](https://eslint.org/docs/latest/use/configure/configuration-files#configuring-eslint). See the [ESLint API reference](/docs/app/api-reference/config/eslint#with-core-web-vitals) for a recommended setup.
> **Good to know**: If an ESLint config is present, `next build` will still run linting in Next.js 15, but this automatic build-time linting will be removed in Next.js 16. Control when linting runs by invoking your linter via npm scripts.
> **Good to know**: Prior to Next.js 16, `next build` ran linting automatically. Now, this automatic build-time linting has been removed. Control when linting runs by invoking your linter via npm scripts.
See the [ESLint Plugin](/docs/app/api-reference/config/next-config-js/eslint) page for more information.
......
......@@ -901,7 +901,6 @@ export default async function build(
reactProductionProfiling = false,
debugOutput = false,
debugPrerender = false,
runLint = true,
noMangling = false,
appDirOnly = false,
isTurbopack = false,
......@@ -1084,16 +1083,10 @@ export default async function build(
experimentalFeatures,
})
const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds)
const shouldLint = !ignoreESLint && runLint
const typeCheckingOptions: Parameters<typeof startTypeChecking>[0] = {
dir,
appDir,
pagesDir,
runLint,
shouldLint,
ignoreESLint,
telemetry,
nextBuildSpan,
config,
......@@ -1132,15 +1125,6 @@ export default async function build(
process.exit(1)
}
const buildLintEvent: EventBuildFeatureUsage = {
featureName: 'build-lint',
invocationCount: shouldLint ? 1 : 0,
}
telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: buildLintEvent,
})
const validFileMatcher = createValidFileMatcher(
config.pageExtensions,
appDir
......
......@@ -2,10 +2,8 @@ import type { NextConfigComplete } from '../server/config-shared'
import type { Telemetry } from '../telemetry/storage'
import type { Span } from '../trace'
import path from 'path'
import * as Log from './output/log'
import { Worker } from '../lib/worker'
import { verifyAndLint } from '../lib/verifyAndLint'
import createSpinner from './spinner'
import { eventTypeCheckCompleted } from '../telemetry/events'
import isError from '../lib/is-error'
......@@ -71,57 +69,36 @@ export async function startTypeChecking({
cacheDir,
config,
dir,
ignoreESLint,
nextBuildSpan,
pagesDir,
runLint,
shouldLint,
telemetry,
appDir,
}: {
cacheDir: string
config: NextConfigComplete
dir: string
ignoreESLint: boolean
nextBuildSpan: Span
pagesDir?: string
runLint: boolean
shouldLint: boolean
telemetry: Telemetry
appDir?: string
}) {
const ignoreTypeScriptErrors = Boolean(config.typescript.ignoreBuildErrors)
const eslintCacheDir = path.join(cacheDir, 'eslint/')
if (ignoreTypeScriptErrors) {
Log.info('Skipping validation of types')
}
if (runLint && ignoreESLint) {
// only print log when build require lint while ignoreESLint is enabled
Log.info('Skipping linting')
}
let typeCheckingAndLintingSpinnerPrefixText: string | undefined
let typeCheckingAndLintingSpinner:
| ReturnType<typeof createSpinner>
| undefined
let typeCheckingSpinnerPrefixText: string | undefined
let typeCheckingSpinner: ReturnType<typeof createSpinner> | undefined
if (!ignoreTypeScriptErrors && shouldLint) {
typeCheckingAndLintingSpinnerPrefixText =
'Linting and checking validity of types'
} else if (!ignoreTypeScriptErrors) {
typeCheckingAndLintingSpinnerPrefixText = 'Checking validity of types'
} else if (shouldLint) {
typeCheckingAndLintingSpinnerPrefixText = 'Linting'
if (!ignoreTypeScriptErrors) {
typeCheckingSpinnerPrefixText = 'Checking validity of types'
}
// we will not create a spinner if both ignoreTypeScriptErrors and ignoreESLint are
// enabled, but we will still verifying project's tsconfig and dependencies.
if (typeCheckingAndLintingSpinnerPrefixText) {
typeCheckingAndLintingSpinner = createSpinner(
typeCheckingAndLintingSpinnerPrefixText
)
// we will not create a spinner if ignoreTypeScriptErrors is enabled,
// but we will still verify project's tsconfig and dependencies.
if (typeCheckingSpinnerPrefixText) {
typeCheckingSpinner = createSpinner(typeCheckingSpinnerPrefixText)
}
const typeCheckStart = process.hrtime()
......@@ -145,18 +122,8 @@ export async function startTypeChecking({
return [resolved, checkEnd] as const
})
),
shouldLint &&
nextBuildSpan.traceChild('verify-and-lint').traceAsyncFn(async () => {
await verifyAndLint(
dir,
eslintCacheDir,
config.eslint?.dirs,
config.experimental.workerThreads,
telemetry
)
}),
])
typeCheckingAndLintingSpinner?.stopAndPersist()
typeCheckingSpinner?.stopAndPersist()
if (!ignoreTypeScriptErrors && verifyResult) {
telemetry.record(
......
......@@ -94,7 +94,6 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
profile,
debug || Boolean(process.env.NEXT_DEBUG_BUILD),
debugPrerender,
lint,
!mangling,
experimentalAppOnly,
isTurbopack,
......
import { red } from './picocolors'
import { Worker } from './worker'
import { existsSync } from 'fs'
import { join } from 'path'
import { ESLINT_DEFAULT_DIRS } from './constants'
import type { Telemetry } from '../telemetry/storage'
import { eventLintCheckCompleted } from '../telemetry/events'
import { CompileError } from './compile-error'
import isError from './is-error'
export async function verifyAndLint(
dir: string,
cacheLocation: string,
configLintDirs: string[] | undefined,
enableWorkerThreads: boolean | undefined,
telemetry: Telemetry
): Promise<void> {
let lintWorkers:
| (Worker & {
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
})
| undefined
try {
lintWorkers = new Worker(require.resolve('./eslint/runLintCheck'), {
exposedMethods: ['runLintCheck'],
debuggerPortOffset: -1,
isolatedMemory: false,
numWorkers: 1,
enableWorkerThreads,
maxRetries: 0,
}) as Worker & {
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
}
const lintDirs = (configLintDirs ?? ESLINT_DEFAULT_DIRS).reduce(
(res: string[], d: string) => {
const currDir = join(dir, d)
if (!existsSync(currDir)) return res
res.push(currDir)
return res
},
[]
)
const lintResults = await lintWorkers?.runLintCheck(dir, lintDirs, {
lintDuringBuild: true,
eslintOptions: {
cacheLocation,
},
})
const lintOutput =
typeof lintResults === 'string' ? lintResults : lintResults?.output
if (typeof lintResults !== 'string' && lintResults?.eventInfo) {
telemetry.record(
eventLintCheckCompleted({
...lintResults.eventInfo,
buildLint: true,
})
)
}
if (typeof lintResults !== 'string' && lintResults?.isError && lintOutput) {
await telemetry.flush()
throw new CompileError(lintOutput)
}
if (lintOutput) {
console.log(lintOutput)
}
} catch (err) {
if (isError(err)) {
if (err.type === 'CompileError' || err instanceof CompileError) {
console.error(red('\nFailed to compile.'))
console.error(err.message)
process.exit(1)
} else if (err.type === 'FatalError') {
console.error(err.message)
process.exit(1)
}
}
throw err
} finally {
try {
lintWorkers?.end()
} catch {}
}
}
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