Skip to content
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
10 changes: 9 additions & 1 deletion packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ async function run(): Promise<void> {
opts.biome = preferredLinter === 'biome'
// No need to set noLinter flag since we check args at runtime
} else {
const linterIndexMap = {
eslint: 0,
biome: 1,
none: 2,
}
const { linter } = await prompts({
onState: onPromptState,
type: 'select',
Expand All @@ -313,7 +318,10 @@ async function run(): Promise<void> {
description: 'Skip linter configuration',
},
],
initial: 0,
initial:
linterIndexMap[
getPrefOrDefault('linter') as keyof typeof linterIndexMap
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
],
] ?? 0,

The code could fail if the user's linter preference contains an unexpected value, causing undefined to be passed as the initial prompt selection.

View Details

Analysis

Undefined initial value passed to prompts when linter preference is invalid

What fails: The linterIndexMap lookup in packages/create-next-app/index.ts:321-324 returns undefined when getPrefOrDefault('linter') returns a value not in the map ('eslint', 'biome', 'none'), causing the prompts library to receive initial: undefined.

How to trigger:

  1. Create or modify the create-next-app config with an invalid linter preference:
# Edit ~/.config/create-next-app/config.json to contain:
{"preferences": {"linter": "invalid-value"}}
  1. Run create-next-app without CLI linter flags to trigger the interactive prompt

Result: The prompts library receives initial: undefined instead of a valid array index, leading to unpredictable default selection behavior.

Expected: Should default to a valid index (0 = ESLint) when the preference value is not recognized, ensuring consistent user experience.

Fix applied: Added nullish coalescing operator ?? 0 to provide fallback to first option (ESLint) when lookup returns undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get at least a default value so wouldn't be undefined

})

opts.eslint = linter === 'eslint'
Expand Down
Loading