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 . ...@@ -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. 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. 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( ...@@ -901,7 +901,6 @@ export default async function build(
reactProductionProfiling = false, reactProductionProfiling = false,
debugOutput = false, debugOutput = false,
debugPrerender = false, debugPrerender = false,
runLint = true,
noMangling = false, noMangling = false,
appDirOnly = false, appDirOnly = false,
isTurbopack = false, isTurbopack = false,
...@@ -1084,16 +1083,10 @@ export default async function build( ...@@ -1084,16 +1083,10 @@ export default async function build(
experimentalFeatures, experimentalFeatures,
}) })
const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds)
const shouldLint = !ignoreESLint && runLint
const typeCheckingOptions: Parameters<typeof startTypeChecking>[0] = { const typeCheckingOptions: Parameters<typeof startTypeChecking>[0] = {
dir, dir,
appDir, appDir,
pagesDir, pagesDir,
runLint,
shouldLint,
ignoreESLint,
telemetry, telemetry,
nextBuildSpan, nextBuildSpan,
config, config,
...@@ -1132,15 +1125,6 @@ export default async function build( ...@@ -1132,15 +1125,6 @@ export default async function build(
process.exit(1) 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( const validFileMatcher = createValidFileMatcher(
config.pageExtensions, config.pageExtensions,
appDir appDir
......
...@@ -2,10 +2,8 @@ import type { NextConfigComplete } from '../server/config-shared' ...@@ -2,10 +2,8 @@ import type { NextConfigComplete } from '../server/config-shared'
import type { Telemetry } from '../telemetry/storage' import type { Telemetry } from '../telemetry/storage'
import type { Span } from '../trace' import type { Span } from '../trace'
import path from 'path'
import * as Log from './output/log' import * as Log from './output/log'
import { Worker } from '../lib/worker' import { Worker } from '../lib/worker'
import { verifyAndLint } from '../lib/verifyAndLint'
import createSpinner from './spinner' import createSpinner from './spinner'
import { eventTypeCheckCompleted } from '../telemetry/events' import { eventTypeCheckCompleted } from '../telemetry/events'
import isError from '../lib/is-error' import isError from '../lib/is-error'
...@@ -71,57 +69,36 @@ export async function startTypeChecking({ ...@@ -71,57 +69,36 @@ export async function startTypeChecking({
cacheDir, cacheDir,
config, config,
dir, dir,
ignoreESLint,
nextBuildSpan, nextBuildSpan,
pagesDir, pagesDir,
runLint,
shouldLint,
telemetry, telemetry,
appDir, appDir,
}: { }: {
cacheDir: string cacheDir: string
config: NextConfigComplete config: NextConfigComplete
dir: string dir: string
ignoreESLint: boolean
nextBuildSpan: Span nextBuildSpan: Span
pagesDir?: string pagesDir?: string
runLint: boolean
shouldLint: boolean
telemetry: Telemetry telemetry: Telemetry
appDir?: string appDir?: string
}) { }) {
const ignoreTypeScriptErrors = Boolean(config.typescript.ignoreBuildErrors) const ignoreTypeScriptErrors = Boolean(config.typescript.ignoreBuildErrors)
const eslintCacheDir = path.join(cacheDir, 'eslint/')
if (ignoreTypeScriptErrors) { if (ignoreTypeScriptErrors) {
Log.info('Skipping validation of types') 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 typeCheckingSpinnerPrefixText: string | undefined
let typeCheckingAndLintingSpinner: let typeCheckingSpinner: ReturnType<typeof createSpinner> | undefined
| ReturnType<typeof createSpinner>
| undefined
if (!ignoreTypeScriptErrors && shouldLint) { if (!ignoreTypeScriptErrors) {
typeCheckingAndLintingSpinnerPrefixText = typeCheckingSpinnerPrefixText = 'Checking validity of types'
'Linting and checking validity of types'
} else if (!ignoreTypeScriptErrors) {
typeCheckingAndLintingSpinnerPrefixText = 'Checking validity of types'
} else if (shouldLint) {
typeCheckingAndLintingSpinnerPrefixText = 'Linting'
} }
// we will not create a spinner if both ignoreTypeScriptErrors and ignoreESLint are // we will not create a spinner if ignoreTypeScriptErrors is enabled,
// enabled, but we will still verifying project's tsconfig and dependencies. // but we will still verify project's tsconfig and dependencies.
if (typeCheckingAndLintingSpinnerPrefixText) { if (typeCheckingSpinnerPrefixText) {
typeCheckingAndLintingSpinner = createSpinner( typeCheckingSpinner = createSpinner(typeCheckingSpinnerPrefixText)
typeCheckingAndLintingSpinnerPrefixText
)
} }
const typeCheckStart = process.hrtime() const typeCheckStart = process.hrtime()
...@@ -145,18 +122,8 @@ export async function startTypeChecking({ ...@@ -145,18 +122,8 @@ export async function startTypeChecking({
return [resolved, checkEnd] as const 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) { if (!ignoreTypeScriptErrors && verifyResult) {
telemetry.record( telemetry.record(
......
...@@ -94,7 +94,6 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => { ...@@ -94,7 +94,6 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
profile, profile,
debug || Boolean(process.env.NEXT_DEBUG_BUILD), debug || Boolean(process.env.NEXT_DEBUG_BUILD),
debugPrerender, debugPrerender,
lint,
!mangling, !mangling,
experimentalAppOnly, experimentalAppOnly,
isTurbopack, 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