Skip to content
TypeScript

chore(lint): enforce react/no-array-index-key (#25112)

Julius Marmingef44fea47a0b3
diff --git a/apps/mobile/modules/t3-source-text/src/SourceText.tsx b/apps/mobile/modules/t3-source-text/src/SourceText.tsx
index aebac31d42c..70bbb4fd48a 100644
--- a/apps/mobile/modules/t3-source-text/src/SourceText.tsx
+++ b/apps/mobile/modules/t3-source-text/src/SourceText.tsx
@@ -28,18 +28,23 @@ export function SourceText({ style, children, nativeTextRef, ...props }: SourceT
</Text>
);
}
- const runs = React.Children.toArray(children).map((child, index) => {
- if (React.isValidElement(child)) return child;
- if (typeof child !== "string" && typeof child !== "number") return null;
- return (
- <T3SourceTextRunNativeComponent
- key={index}
- style={flattenedStyle}
- {...flattenedStyle}
- text={String(child)}
- />
- );
- });
+ const runs = React.Children.toArray(children).map(
+ (
+ child,
+ index,
+ ) => /* oxlint-disable react/no-array-index-key -- Native text runs are stateless positions within the supplied text. */ {
+ if (React.isValidElement(child)) return child;
+ if (typeof child !== "string" && typeof child !== "number") return null;
+ return (
+ <T3SourceTextRunNativeComponent
+ key={index}
+ style={flattenedStyle}
+ {...flattenedStyle}
+ text={String(child)}
+ />
+ );
+ } /* oxlint-enable react/no-array-index-key */,
+ );
if (isAncestor) {
return <TextAncestorContext.Provider value={contextValue}>{runs}</TextAncestorContext.Provider>;
}
diff --git a/apps/mobile/src/components/ComposerContextSheet.tsx b/apps/mobile/src/components/ComposerContextSheet.tsx
index 2e93aee6381..20c7485ef15 100644
--- a/apps/mobile/src/components/ComposerContextSheet.tsx
+++ b/apps/mobile/src/components/ComposerContextSheet.tsx
@@ -268,18 +268,23 @@ export function ComposerContextSheet(props: {
<ContextField label="Comment" value={record.comment} />
<ContextField label="Selection" value={record.targetSummary} />
<ContextField label="Requested changes" value={record.styleChanges.join("\n")} />
- {record.elements?.map((element, index) => (
- <View key={`${element.selector ?? element.tagName}:${index}`} className="gap-3">
- <ContextField
- label="Element"
- value={element.componentName ?? element.tagName}
- />
- <ContextField label="Selector" value={element.selector} code />
- <ContextSource source={element.source} />
- <ContextField label="HTML" value={element.htmlPreview} code />
- <ContextField label="Styles" value={element.styles} code />
- </View>
- ))}
+ {record.elements?.map(
+ (element, index) => (
+ /* oxlint-disable react/no-array-index-key -- Captured DOM elements are a fixed snapshot without persistent element IDs. */ <View
+ key={`${element.selector ?? element.tagName}:${index}`}
+ className="gap-3"
+ >
+ <ContextField
+ label="Element"
+ value={element.componentName ?? element.tagName}
+ />
+ <ContextField label="Selector" value={element.selector} code />
+ <ContextSource source={element.source} />
+ <ContextField label="HTML" value={element.htmlPreview} code />
+ <ContextField label="Styles" value={element.styles} code />
+ </View>
+ ) /* oxlint-enable react/no-array-index-key */,
+ )}
</>
) : null}
{record.kind === "element" ? (
diff --git a/apps/mobile/src/features/files/SourceFileSurface.tsx b/apps/mobile/src/features/files/SourceFileSurface.tsx
index a030d97af5c..e0cb29494f1 100644
--- a/apps/mobile/src/features/files/SourceFileSurface.tsx
+++ b/apps/mobile/src/features/files/SourceFileSurface.tsx
@@ -280,34 +280,41 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
}}
>
{selectableTokens
- ? lines.map((line, index) => {
- const lineTokens = selectableTokens[index] ?? null;
- const body =
- lineTokens && lineTokens.length > 0
- ? lineTokens.map((token, tokenIndex) => (
- <SourceText
- key={`${index}:${tokenIndex}`}
- style={{
- color: token.color ?? foreground,
- fontWeight:
- token.fontStyle !== null && (token.fontStyle & 2) === 2 ? "700" : "400",
- fontStyle:
- token.fontStyle !== null && (token.fontStyle & 1) === 1
- ? "italic"
- : "normal",
- }}
- >
- {token.content}
- </SourceText>
- ))
- : line;
- return (
- <SourceText key={index}>
- {body}
- {index < lines.length - 1 ? "\n" : ""}
- </SourceText>
- );
- })
+ ? lines.map(
+ (
+ line,
+ index,
+ ) => /* oxlint-disable react/no-array-index-key -- Source lines and highlight tokens are stateless positions within the loaded file. */ {
+ const lineTokens = selectableTokens[index] ?? null;
+ const body =
+ lineTokens && lineTokens.length > 0
+ ? lineTokens.map((token, tokenIndex) => (
+ <SourceText
+ key={`${index}:${tokenIndex}`}
+ style={{
+ color: token.color ?? foreground,
+ fontWeight:
+ token.fontStyle !== null && (token.fontStyle & 2) === 2
+ ? "700"
+ : "400",
+ fontStyle:
+ token.fontStyle !== null && (token.fontStyle & 1) === 1
+ ? "italic"
+ : "normal",
+ }}
+ >
+ {token.content}
+ </SourceText>
+ ))
+ : line;
+ return (
+ <SourceText key={index}>
+ {body}
+ {index < lines.length - 1 ? "\n" : ""}
+ </SourceText>
+ );
+ } /* oxlint-enable react/no-array-index-key */,
+ )
: normalizedContents}
</SourceText>
) : null;
diff --git a/apps/mobile/src/features/review/ReviewCommentCard.tsx b/apps/mobile/src/features/review/ReviewCommentCard.tsx
index 01596bd6234..ef1eff43b45 100644
--- a/apps/mobile/src/features/review/ReviewCommentCard.tsx
+++ b/apps/mobile/src/features/review/ReviewCommentCard.tsx
@@ -219,23 +219,27 @@ export const ReviewCommentCard = memo(function ReviewCommentCard(props: {
}}
>
{snippetTokens
- ? snippetTokens.map((line, lineIndex) => (
- <NativeText key={lineIndex}>
- {lineIndex > 0 ? "\n" : ""}
- {line.map((token, tokenIndex) => (
- <NativeText
- key={tokenIndex}
- style={{
- color: token.color ?? props.colors.text,
- fontStyle: (token.fontStyle ?? 0) & 1 ? "italic" : "normal",
- fontWeight: (token.fontStyle ?? 0) & 2 ? "700" : "400",
- }}
- >
- {token.content}
- </NativeText>
- ))}
- </NativeText>
- ))
+ ? snippetTokens.map(
+ (line, lineIndex) => (
+ /* oxlint-disable react/no-array-index-key -- Highlight tokens are stateless positions within this immutable snippet. */ <NativeText
+ key={lineIndex}
+ >
+ {lineIndex > 0 ? "\n" : ""}
+ {line.map((token, tokenIndex) => (
+ <NativeText
+ key={tokenIndex}
+ style={{
+ color: token.color ?? props.colors.text,
+ fontStyle: (token.fontStyle ?? 0) & 1 ? "italic" : "normal",
+ fontWeight: (token.fontStyle ?? 0) & 2 ? "700" : "400",
+ }}
+ >
+ {token.content}
+ </NativeText>
+ ))}
+ </NativeText>
+ ) /* oxlint-enable react/no-array-index-key */,
+ )
: props.comment.diff.trim()}
</NativeText>
</ScrollView>
diff --git a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx b/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
index c74bc685d34..99e445d483c 100644
--- a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
+++ b/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
@@ -67,41 +67,43 @@ export function TerminalContextSheet(props: {
Tap the first and last line to select a range.
</Text>
<View className="overflow-hidden rounded-xl bg-card-alt">
- {lines.map((line, index) => (
- <Pressable
- key={index}
- accessibilityRole="button"
- accessibilityLabel={`Line ${index + 1}: ${line}`}
- accessibilityState={{ selected: index >= range.start && index <= range.end }}
- onPress={() => {
- if (anchor === null) {
- setAnchor(index);
- setRange({ start: index, end: index });
- } else {
- setRange({ start: Math.min(anchor, index), end: Math.max(anchor, index) });
- setAnchor(null);
+ {lines.map(
+ (line, index) => (
+ /* oxlint-disable react/no-array-index-key -- Selection is addressed by line number in this captured terminal snapshot. */ <Pressable
+ key={index}
+ accessibilityRole="button"
+ accessibilityLabel={`Line ${index + 1}: ${line}`}
+ accessibilityState={{ selected: index >= range.start && index <= range.end }}
+ onPress={() => {
+ if (anchor === null) {
+ setAnchor(index);
+ setRange({ start: index, end: index });
+ } else {
+ setRange({ start: Math.min(anchor, index), end: Math.max(anchor, index) });
+ setAnchor(null);
+ }
+ }}
+ className={
+ index >= range.start && index <= range.end
+ ? "flex-row gap-3 bg-primary/10 px-3 py-2"
+ : "flex-row gap-3 px-3 py-2"
}
- }}
- className={
- index >= range.start && index <= range.end
- ? "flex-row gap-3 bg-primary/10 px-3 py-2"
- : "flex-row gap-3 px-3 py-2"
- }
- >
- <Text
- className="w-8 text-right text-sm text-foreground-muted"
- style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
>
- {index + 1}
- </Text>
- <Text
- className="flex-1 text-sm text-foreground"
- style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
- >
- {line || " "}
- </Text>
- </Pressable>
- ))}
+ <Text
+ className="w-8 text-right text-sm text-foreground-muted"
+ style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
+ >
+ {index + 1}
+ </Text>
+ <Text
+ className="flex-1 text-sm text-foreground"
+ style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
+ >
+ {line || " "}
+ </Text>
+ </Pressable>
+ ) /* oxlint-enable react/no-array-index-key */,
+ )}
</View>
</ScrollView>
<View
diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
index 7018f992789..91576c47299 100644
--- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx
+++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
@@ -1225,11 +1225,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
) : null}
{providerInstance ? (
<View className="flex-row items-center">
- {providerDrivers.slice(0, -1).map((driver, index) => (
- <View key={`${driver}:${index}`} className="-mr-1 opacity-30">
- <ProviderIcon provider={driver} size={12} />
- </View>
- ))}
+ {providerDrivers.slice(0, -1).map(
+ (driver, index) => (
+ /* oxlint-disable react/no-array-index-key -- Provider history can repeat a driver; these decorative icons have no local state. */ <View
+ key={`${driver}:${index}`}
+ className="-mr-1 opacity-30"
+ >
+ <ProviderIcon provider={driver} size={12} />
+ </View>
+ ) /* oxlint-enable react/no-array-index-key */,
+ )}
<ProviderInstanceIcon
iconUrl={providerIconUrl}
provider={providerInstance.driverKind}
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsx
index 9659abc144b..259cdb399d1 100644
--- a/apps/mobile/src/features/threads/thread-work-log.tsx
+++ b/apps/mobile/src/features/threads/thread-work-log.tsx
@@ -1214,18 +1214,20 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
call.argsText,
]
.filter((line) => Boolean(line))
- .map((line, index) =>
- typeof line === "string" ? (
- <Text
- key={`${index}:${line}`}
- selectable
- className="font-mono text-2xs leading-normal text-foreground"
- >
- {line}
- </Text>
- ) : (
- line
- ),
+ .map(
+ (line, index) =>
+ /* oxlint-disable react/no-array-index-key -- Log lines are stateless positions within this output. */ typeof line ===
+ "string" ? (
+ <Text
+ key={`${index}:${line}`}
+ selectable
+ className="font-mono text-2xs leading-normal text-foreground"
+ >
+ {line}
+ </Text>
+ ) : (
+ line
+ ) /* oxlint-enable react/no-array-index-key */,
)
) : fullDetail ? (
<Text selectable className="font-mono text-2xs leading-normal text-foreground-muted">
diff --git a/apps/web/src/components/pullRequest/PullRequestChecksPopover.tsx b/apps/web/src/components/pullRequest/PullRequestChecksPopover.tsx
index 2b43d1262e9..cfcea204a56 100644
--- a/apps/web/src/components/pullRequest/PullRequestChecksPopover.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestChecksPopover.tsx
@@ -79,36 +79,38 @@ function ChecksBody({
: "grid-cols-[auto_minmax(0,1fr)_auto]",
)}
>
- {visibleChecks.map((check, index) => (
- <li
- key={`${index}:${check.name}`}
- className="col-span-full grid grid-cols-subgrid items-center text-xs"
- >
- <PullRequestCheckStatusIcon status={check.status} />
- <Tooltip>
- <TooltipTrigger render={<span className="min-w-0 truncate">{check.name}</span>} />
- <TooltipPopup side="top">{check.description ?? check.name}</TooltipPopup>
- </Tooltip>
- <span className="justify-self-end whitespace-nowrap text-muted-foreground">
- {pullRequestCheckStatusLabel(check)}
- </span>
- {check.url === null ? null : (
- <button
- type="button"
- className="text-primary hover:underline"
- onClick={() => {
- if (!check.url) return;
- void openLink(check.url).catch((error: unknown) => {
- console.error(error);
- toastManager.add({ type: "error", title: "Unable to open check details" });
- });
- }}
- >
- Details
- </button>
- )}
- </li>
- ))}
+ {visibleChecks.map(
+ (check, index) => (
+ /* oxlint-disable react/no-array-index-key -- Check names can repeat; these status rows have no local state. */ <li
+ key={`${index}:${check.name}`}
+ className="col-span-full grid grid-cols-subgrid items-center text-xs"
+ >
+ <PullRequestCheckStatusIcon status={check.status} />
+ <Tooltip>
+ <TooltipTrigger render={<span className="min-w-0 truncate">{check.name}</span>} />
+ <TooltipPopup side="top">{check.description ?? check.name}</TooltipPopup>
+ </Tooltip>
+ <span className="justify-self-end whitespace-nowrap text-muted-foreground">
+ {pullRequestCheckStatusLabel(check)}
+ </span>
+ {check.url === null ? null : (
+ <button
+ type="button"
+ className="text-primary hover:underline"
+ onClick={() => {
+ if (!check.url) return;
+ void openLink(check.url).catch((error: unknown) => {
+ console.error(error);
+ toastManager.add({ type: "error", title: "Unable to open check details" });
+ });
+ }}
+ >
+ Details
+ </button>
+ )}
+ </li>
+ ) /* oxlint-enable react/no-array-index-key */,
+ )}
</ul>
</ScrollArea>
{canCollapse ? (
diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
index 8441a97bde9..39aa50593b3 100644
--- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
@@ -795,46 +795,51 @@ export function PullRequestSummaryTab({
) : detail.checks.length === 0 ? (
<p className="text-xs text-muted-foreground">No checks reported.</p>
) : (
- detail.checks.map((check, index) => {
- const finding = { kind: "check", check } as const;
- const failing = check.status === "failure" || check.status === "cancelled";
- return (
- <div
- key={`${index}:${check.name}:${check.url ?? ""}`}
- className="group flex items-center gap-2 rounded-md pr-1 hover:bg-accent/60"
- >
- <button
- type="button"
- disabled={!check.url}
- onClick={() => check.url && openCheck(check.url)}
- className={cn(
- "flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-2 text-left text-xs leading-5 [&>svg]:mt-0.5",
- check.url ? "cursor-pointer" : "cursor-default",
- )}
- >
- <PullRequestCheckStatusIcon status={check.status} />
- <span className="min-w-0 flex-1 wrap-anywhere">{check.name}</span>
- <span className="shrink-0 text-muted-foreground">
- {pullRequestCheckStatusLabel(check)}
- </span>
- </button>
- {onFixFinding && failing ? (
- <Button
- size="xs"
- variant="ghost"
- className="shrink-0"
- disabled={pendingFinding !== null && pendingFinding !== undefined}
- onClick={() => onFixFinding(finding)}
+ detail.checks.map(
+ (
+ check,
+ index,
+ ) => /* oxlint-disable react/no-array-index-key -- Check names and URLs can repeat; these status rows have no local state. */ {
+ const finding = { kind: "check", check } as const;
+ const failing = check.status === "failure" || check.status === "cancelled";
+ return (
+ <div
+ key={`${index}:${check.name}:${check.url ?? ""}`}
+ className="group flex items-center gap-2 rounded-md pr-1 hover:bg-accent/60"
>
- <HammerIcon className="size-3" />
- {pendingFinding === pullRequestFindingKey(finding)
- ? "Preparing..."
- : fixCheckLabel}
- </Button>
- ) : null}
- </div>
- );
- })
+ <button
+ type="button"
+ disabled={!check.url}
+ onClick={() => check.url && openCheck(check.url)}
+ className={cn(
+ "flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-2 text-left text-xs leading-5 [&>svg]:mt-0.5",
+ check.url ? "cursor-pointer" : "cursor-default",
+ )}
+ >
+ <PullRequestCheckStatusIcon status={check.status} />
+ <span className="min-w-0 flex-1 wrap-anywhere">{check.name}</span>
+ <span className="shrink-0 text-muted-foreground">
+ {pullRequestCheckStatusLabel(check)}
+ </span>
+ </button>
+ {onFixFinding && failing ? (
+ <Button
+ size="xs"
+ variant="ghost"
+ className="shrink-0"
+ disabled={pendingFinding !== null && pendingFinding !== undefined}
+ onClick={() => onFixFinding(finding)}
+ >
+ <HammerIcon className="size-3" />
+ {pendingFinding === pullRequestFindingKey(finding)
+ ? "Preparing..."
+ : fixCheckLabel}
+ </Button>
+ ) : null}
+ </div>
+ );
+ } /* oxlint-enable react/no-array-index-key */,
+ )
)}
</Section>
diff --git a/vite.config.ts b/vite.config.ts
index f865dc62d2f..2a48daa13ac 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -216,6 +216,7 @@ export default defineConfig({
perf: "warn",
},
rules: {
+ "react/no-array-index-key": "error",
"react/no-unstable-nested-components": "error",
"react/static-components": "error",
"react/capitalized-calls": "error",