Skip to content

Commit

Permalink
fix: disable linting on builds without a eslint configuration present
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed May 24, 2024
1 parent 08b75b7 commit 7d00a39
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 57 deletions.
36 changes: 2 additions & 34 deletions test/integration/eslint/test/lint-cache.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
import fs from 'fs-extra'
import os from 'os'

import { join } from 'path'

import findUp from 'next/dist/compiled/find-up'
import { File, nextBuild, nextLint } from 'next-test-utils'

const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
const dirCustomConfig = join(__dirname, '../custom-config')
const dirWebVitalsConfig = join(__dirname, '../config-core-web-vitals')
const dirPluginRecommendedConfig = join(
__dirname,
'../plugin-recommended-config'
)
const dirPluginCoreWebVitalsConfig = join(
__dirname,
'../plugin-core-web-vitals-config'
)
const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
const dirBaseDirectories = join(__dirname, '../base-directories')
const dirBaseDirectoriesConfigFile = new File(
join(dirBaseDirectories, '/next.config.js')
)
const dirCustomDirectories = join(__dirname, '../custom-directories')
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
const dirInvalidOlderEslintVersion = join(
__dirname,
'../invalid-eslint-version'
)
const dirMaxWarnings = join(__dirname, '../max-warnings')
const dirEmptyDirectory = join(__dirname, '../empty-directory')
const dirEslintIgnore = join(__dirname, '../eslint-ignore')
const dirNoEslintPlugin = join(__dirname, '../no-eslint-plugin')
const dirNoConfig = join(__dirname, '../no-config')
import { nextLint } from 'next-test-utils'

const dirEslintCache = join(__dirname, '../eslint-cache')
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
const dirFileLinting = join(__dirname, '../file-linting')
const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting')
const dirTypescript = join(__dirname, '../with-typescript')

test('eslint caching is enabled by default', async () => {
const cacheDir = join(dirEslintCache, '.next', 'cache')
Expand Down
39 changes: 16 additions & 23 deletions test/integration/eslint/test/next-build.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import fs from 'fs-extra'
import os from 'os'

import { join } from 'path'

import findUp from 'next/dist/compiled/find-up'
import { File, nextBuild, nextLint } from 'next-test-utils'
import { nextBuild } from 'next-test-utils'

const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
const dirCustomConfig = join(__dirname, '../custom-config')
const dirWebVitalsConfig = join(__dirname, '../config-core-web-vitals')
const dirPluginRecommendedConfig = join(
__dirname,
'../plugin-recommended-config'
)
const dirPluginCoreWebVitalsConfig = join(
__dirname,
'../plugin-core-web-vitals-config'
)
const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
const dirBaseDirectories = join(__dirname, '../base-directories')
const dirBaseDirectoriesConfigFile = new File(
join(dirBaseDirectories, '/next.config.js')
)
const dirCustomDirectories = join(__dirname, '../custom-directories')
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
const dirInvalidOlderEslintVersion = join(
__dirname,
'../invalid-eslint-version'
)
const dirMaxWarnings = join(__dirname, '../max-warnings')
const dirEmptyDirectory = join(__dirname, '../empty-directory')
const dirEslintIgnore = join(__dirname, '../eslint-ignore')
const dirNoEslintPlugin = join(__dirname, '../no-eslint-plugin')
const dirNoConfig = join(__dirname, '../no-config')
const dirEslintCache = join(__dirname, '../eslint-cache')
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
const dirFileLinting = join(__dirname, '../file-linting')
const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting')
const dirTypescript = join(__dirname, '../with-typescript')

describe('Next Build', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
Expand All @@ -50,6 +30,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirFirstTimeSetup, [], {
stdout: true,
stderr: true,
lint: true,
})
const output = stdout + stderr

Expand All @@ -62,6 +43,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirCustomConfig, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -77,6 +59,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirIgnoreDuringBuilds, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -90,6 +73,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirBaseDirectories, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand Down Expand Up @@ -121,6 +105,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirCustomDirectories, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -140,6 +125,7 @@ describe('Next Build', () => {
{
stdout: true,
stderr: true,
lint: true,
}
)

Expand All @@ -153,6 +139,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirEmptyDirectory, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -168,6 +155,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirEslintIgnore, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -183,6 +171,7 @@ describe('Next Build', () => {
const { stdout, stderr } = await nextBuild(dirNoEslintPlugin, [], {
stdout: true,
stderr: true,
lint: true,
})

const output = stdout + stderr
Expand All @@ -195,7 +184,9 @@ describe('Next Build', () => {
const cacheDir = join(dirEslintCache, '.next', 'cache')

await fs.remove(cacheDir)
await nextBuild(dirEslintCache, [])
await nextBuild(dirEslintCache, [], {
lint: true,
})

const files = await fs.readdir(join(cacheDir, 'eslint/'))
const cacheExists = files.some((f) => /\.cache/.test(f))
Expand All @@ -210,7 +201,9 @@ describe('Next Build', () => {
await fs.remove(oldCacheDir)
await fs.remove(newCacheDir)

await nextBuild(dirEslintCacheCustomDir, [])
await nextBuild(dirEslintCacheCustomDir, [], {
lint: true,
})

expect(fs.existsSync(oldCacheDir)).toBe(false)

Expand Down
3 changes: 3 additions & 0 deletions test/integration/telemetry/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ describe('config telemetry', () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
lint: true,
})
await fs.remove(path.join(appDir, '.eslintrc'))

Expand Down Expand Up @@ -222,6 +223,7 @@ describe('config telemetry', () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
lint: true,
})
await fs.remove(nextConfig)

Expand Down Expand Up @@ -266,6 +268,7 @@ describe('config telemetry', () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
lint: true,
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
Expand Down
1 change: 1 addition & 0 deletions test/lib/next-modes/next-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class NextStartInstance extends NextInstance {
if (this.buildCommand) {
buildArgs = this.buildCommand.split(' ')
}

if (this.startCommand) {
startArgs = this.startCommand.split(' ')
}
Expand Down
12 changes: 12 additions & 0 deletions test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ export interface NextOptions {
stdout?: true | 'log'
ignoreFail?: boolean

/**
* If true, this enables the linting step in the build process. If false or
* undefined, it adds a `--no-lint` flag to the build command.
*/
lint?: boolean

onStdout?: (data: any) => void
onStderr?: (data: any) => void
}
Expand Down Expand Up @@ -442,6 +448,12 @@ export function nextBuild(
args: string[] = [],
opts: NextOptions = {}
) {
// If the build hasn't requested it to be linted explicitly, disable linting
// if it's not already disabled.
if (!opts.lint && !args.includes('--no-lint')) {
args.push('--no-lint')
}

return runNextCommand(['build', dir, ...args], opts)
}

Expand Down

0 comments on commit 7d00a39

Please sign in to comment.