Skip to content

Commit 4084ceb

Browse files
chore(lint): enforce react/no-array-index-key
1 parent a9cf5c5 commit 4084ceb

10 files changed

Lines changed: 226 additions & 188 deletions

File tree

‎apps/mobile/modules/t3-source-text/src/SourceText.tsx‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ export function SourceText({ style, children, nativeTextRef, ...props }: SourceT
2828
</Text>
2929
);
3030
}
31-
const runs = React.Children.toArray(children).map((child, index) => {
32-
if (React.isValidElement(child)) return child;
33-
if (typeof child !== "string" && typeof child !== "number") return null;
34-
return (
35-
<T3SourceTextRunNativeComponent
36-
key={index}
37-
style={flattenedStyle}
38-
{...flattenedStyle}
39-
text={String(child)}
40-
/>
41-
);
42-
});
31+
const runs = React.Children.toArray(children).map(
32+
(
33+
child,
34+
index,
35+
) => /* oxlint-disable react/no-array-index-key -- Native text runs are stateless positions within the supplied text. */ {
36+
if (React.isValidElement(child)) return child;
37+
if (typeof child !== "string" && typeof child !== "number") return null;
38+
return (
39+
<T3SourceTextRunNativeComponent
40+
key={index}
41+
style={flattenedStyle}
42+
{...flattenedStyle}
43+
text={String(child)}
44+
/>
45+
);
46+
} /* oxlint-enable react/no-array-index-key */,
47+
);
4348
if (isAncestor) {
4449
return <TextAncestorContext.Provider value={contextValue}>{runs}</TextAncestorContext.Provider>;
4550
}

‎apps/mobile/src/components/ComposerContextSheet.tsx‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,23 @@ export function ComposerContextSheet(props: {
268268
<ContextField label="Comment" value={record.comment} />
269269
<ContextField label="Selection" value={record.targetSummary} />
270270
<ContextField label="Requested changes" value={record.styleChanges.join("\n")} />
271-
{record.elements?.map((element, index) => (
272-
<View key={`${element.selector ?? element.tagName}:${index}`} className="gap-3">
273-
<ContextField
274-
label="Element"
275-
value={element.componentName ?? element.tagName}
276-
/>
277-
<ContextField label="Selector" value={element.selector} code />
278-
<ContextSource source={element.source} />
279-
<ContextField label="HTML" value={element.htmlPreview} code />
280-
<ContextField label="Styles" value={element.styles} code />
281-
</View>
282-
))}
271+
{record.elements?.map(
272+
(element, index) => (
273+
/* oxlint-disable react/no-array-index-key -- Captured DOM elements are a fixed snapshot without persistent element IDs. */ <View
274+
key={`${element.selector ?? element.tagName}:${index}`}
275+
className="gap-3"
276+
>
277+
<ContextField
278+
label="Element"
279+
value={element.componentName ?? element.tagName}
280+
/>
281+
<ContextField label="Selector" value={element.selector} code />
282+
<ContextSource source={element.source} />
283+
<ContextField label="HTML" value={element.htmlPreview} code />
284+
<ContextField label="Styles" value={element.styles} code />
285+
</View>
286+
) /* oxlint-enable react/no-array-index-key */,
287+
)}
283288
</>
284289
) : null}
285290
{record.kind === "element" ? (

‎apps/mobile/src/features/files/SourceFileSurface.tsx‎

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -280,34 +280,41 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
280280
}}
281281
>
282282
{selectableTokens
283-
? lines.map((line, index) => {
284-
const lineTokens = selectableTokens[index] ?? null;
285-
const body =
286-
lineTokens && lineTokens.length > 0
287-
? lineTokens.map((token, tokenIndex) => (
288-
<SourceText
289-
key={`${index}:${tokenIndex}`}
290-
style={{
291-
color: token.color ?? foreground,
292-
fontWeight:
293-
token.fontStyle !== null && (token.fontStyle & 2) === 2 ? "700" : "400",
294-
fontStyle:
295-
token.fontStyle !== null && (token.fontStyle & 1) === 1
296-
? "italic"
297-
: "normal",
298-
}}
299-
>
300-
{token.content}
301-
</SourceText>
302-
))
303-
: line;
304-
return (
305-
<SourceText key={index}>
306-
{body}
307-
{index < lines.length - 1 ? "\n" : ""}
308-
</SourceText>
309-
);
310-
})
283+
? lines.map(
284+
(
285+
line,
286+
index,
287+
) => /* oxlint-disable react/no-array-index-key -- Source lines and highlight tokens are stateless positions within the loaded file. */ {
288+
const lineTokens = selectableTokens[index] ?? null;
289+
const body =
290+
lineTokens && lineTokens.length > 0
291+
? lineTokens.map((token, tokenIndex) => (
292+
<SourceText
293+
key={`${index}:${tokenIndex}`}
294+
style={{
295+
color: token.color ?? foreground,
296+
fontWeight:
297+
token.fontStyle !== null && (token.fontStyle & 2) === 2
298+
? "700"
299+
: "400",
300+
fontStyle:
301+
token.fontStyle !== null && (token.fontStyle & 1) === 1
302+
? "italic"
303+
: "normal",
304+
}}
305+
>
306+
{token.content}
307+
</SourceText>
308+
))
309+
: line;
310+
return (
311+
<SourceText key={index}>
312+
{body}
313+
{index < lines.length - 1 ? "\n" : ""}
314+
</SourceText>
315+
);
316+
} /* oxlint-enable react/no-array-index-key */,
317+
)
311318
: normalizedContents}
312319
</SourceText>
313320
) : null;

‎apps/mobile/src/features/review/ReviewCommentCard.tsx‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,27 @@ export const ReviewCommentCard = memo(function ReviewCommentCard(props: {
219219
}}
220220
>
221221
{snippetTokens
222-
? snippetTokens.map((line, lineIndex) => (
223-
<NativeText key={lineIndex}>
224-
{lineIndex > 0 ? "\n" : ""}
225-
{line.map((token, tokenIndex) => (
226-
<NativeText
227-
key={tokenIndex}
228-
style={{
229-
color: token.color ?? props.colors.text,
230-
fontStyle: (token.fontStyle ?? 0) & 1 ? "italic" : "normal",
231-
fontWeight: (token.fontStyle ?? 0) & 2 ? "700" : "400",
232-
}}
233-
>
234-
{token.content}
235-
</NativeText>
236-
))}
237-
</NativeText>
238-
))
222+
? snippetTokens.map(
223+
(line, lineIndex) => (
224+
/* oxlint-disable react/no-array-index-key -- Highlight tokens are stateless positions within this immutable snippet. */ <NativeText
225+
key={lineIndex}
226+
>
227+
{lineIndex > 0 ? "\n" : ""}
228+
{line.map((token, tokenIndex) => (
229+
<NativeText
230+
key={tokenIndex}
231+
style={{
232+
color: token.color ?? props.colors.text,
233+
fontStyle: (token.fontStyle ?? 0) & 1 ? "italic" : "normal",
234+
fontWeight: (token.fontStyle ?? 0) & 2 ? "700" : "400",
235+
}}
236+
>
237+
{token.content}
238+
</NativeText>
239+
))}
240+
</NativeText>
241+
) /* oxlint-enable react/no-array-index-key */,
242+
)
239243
: props.comment.diff.trim()}
240244
</NativeText>
241245
</ScrollView>

‎apps/mobile/src/features/terminal/TerminalContextSheet.tsx‎

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,43 @@ export function TerminalContextSheet(props: {
6767
Tap the first and last line to select a range.
6868
</Text>
6969
<View className="overflow-hidden rounded-xl bg-card-alt">
70-
{lines.map((line, index) => (
71-
<Pressable
72-
key={index}
73-
accessibilityRole="button"
74-
accessibilityLabel={`Line ${index + 1}: ${line}`}
75-
accessibilityState={{ selected: index >= range.start && index <= range.end }}
76-
onPress={() => {
77-
if (anchor === null) {
78-
setAnchor(index);
79-
setRange({ start: index, end: index });
80-
} else {
81-
setRange({ start: Math.min(anchor, index), end: Math.max(anchor, index) });
82-
setAnchor(null);
70+
{lines.map(
71+
(line, index) => (
72+
/* oxlint-disable react/no-array-index-key -- Selection is addressed by line number in this captured terminal snapshot. */ <Pressable
73+
key={index}
74+
accessibilityRole="button"
75+
accessibilityLabel={`Line ${index + 1}: ${line}`}
76+
accessibilityState={{ selected: index >= range.start && index <= range.end }}
77+
onPress={() => {
78+
if (anchor === null) {
79+
setAnchor(index);
80+
setRange({ start: index, end: index });
81+
} else {
82+
setRange({ start: Math.min(anchor, index), end: Math.max(anchor, index) });
83+
setAnchor(null);
84+
}
85+
}}
86+
className={
87+
index >= range.start && index <= range.end
88+
? "flex-row gap-3 bg-primary/10 px-3 py-2"
89+
: "flex-row gap-3 px-3 py-2"
8390
}
84-
}}
85-
className={
86-
index >= range.start && index <= range.end
87-
? "flex-row gap-3 bg-primary/10 px-3 py-2"
88-
: "flex-row gap-3 px-3 py-2"
89-
}
90-
>
91-
<Text
92-
className="w-8 text-right text-sm text-foreground-muted"
93-
style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
9491
>
95-
{index + 1}
96-
</Text>
97-
<Text
98-
className="flex-1 text-sm text-foreground"
99-
style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
100-
>
101-
{line || " "}
102-
</Text>
103-
</Pressable>
104-
))}
92+
<Text
93+
className="w-8 text-right text-sm text-foreground-muted"
94+
style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
95+
>
96+
{index + 1}
97+
</Text>
98+
<Text
99+
className="flex-1 text-sm text-foreground"
100+
style={{ fontFamily: REVIEW_MONO_FONT_FAMILY }}
101+
>
102+
{line || " "}
103+
</Text>
104+
</Pressable>
105+
) /* oxlint-enable react/no-array-index-key */,
106+
)}
105107
</View>
106108
</ScrollView>
107109
<View

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,11 +1225,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
12251225
) : null}
12261226
{providerInstance ? (
12271227
<View className="flex-row items-center">
1228-
{providerDrivers.slice(0, -1).map((driver, index) => (
1229-
<View key={`${driver}:${index}`} className="-mr-1 opacity-30">
1230-
<ProviderIcon provider={driver} size={12} />
1231-
</View>
1232-
))}
1228+
{providerDrivers.slice(0, -1).map(
1229+
(driver, index) => (
1230+
/* oxlint-disable react/no-array-index-key -- Provider history can repeat a driver; these decorative icons have no local state. */ <View
1231+
key={`${driver}:${index}`}
1232+
className="-mr-1 opacity-30"
1233+
>
1234+
<ProviderIcon provider={driver} size={12} />
1235+
</View>
1236+
) /* oxlint-enable react/no-array-index-key */,
1237+
)}
12331238
<ProviderInstanceIcon
12341239
iconUrl={providerIconUrl}
12351240
provider={providerInstance.driverKind}

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,18 +1214,20 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
12141214
call.argsText,
12151215
]
12161216
.filter((line) => Boolean(line))
1217-
.map((line, index) =>
1218-
typeof line === "string" ? (
1219-
<Text
1220-
key={`${index}:${line}`}
1221-
selectable
1222-
className="font-mono text-2xs leading-normal text-foreground"
1223-
>
1224-
{line}
1225-
</Text>
1226-
) : (
1227-
line
1228-
),
1217+
.map(
1218+
(line, index) =>
1219+
/* oxlint-disable react/no-array-index-key -- Log lines are stateless positions within this output. */ typeof line ===
1220+
"string" ? (
1221+
<Text
1222+
key={`${index}:${line}`}
1223+
selectable
1224+
className="font-mono text-2xs leading-normal text-foreground"
1225+
>
1226+
{line}
1227+
</Text>
1228+
) : (
1229+
line
1230+
) /* oxlint-enable react/no-array-index-key */,
12291231
)
12301232
) : fullDetail ? (
12311233
<Text selectable className="font-mono text-2xs leading-normal text-foreground-muted">

‎apps/web/src/components/pullRequest/PullRequestChecksPopover.tsx‎

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,38 @@ function ChecksBody({
7979
: "grid-cols-[auto_minmax(0,1fr)_auto]",
8080
)}
8181
>
82-
{visibleChecks.map((check, index) => (
83-
<li
84-
key={`${index}:${check.name}`}
85-
className="col-span-full grid grid-cols-subgrid items-center text-xs"
86-
>
87-
<PullRequestCheckStatusIcon status={check.status} />
88-
<Tooltip>
89-
<TooltipTrigger render={<span className="min-w-0 truncate">{check.name}</span>} />
90-
<TooltipPopup side="top">{check.description ?? check.name}</TooltipPopup>
91-
</Tooltip>
92-
<span className="justify-self-end whitespace-nowrap text-muted-foreground">
93-
{pullRequestCheckStatusLabel(check)}
94-
</span>
95-
{check.url === null ? null : (
96-
<button
97-
type="button"
98-
className="text-primary hover:underline"
99-
onClick={() => {
100-
if (!check.url) return;
101-
void openLink(check.url).catch((error: unknown) => {
102-
console.error(error);
103-
toastManager.add({ type: "error", title: "Unable to open check details" });
104-
});
105-
}}
106-
>
107-
Details
108-
</button>
109-
)}
110-
</li>
111-
))}
82+
{visibleChecks.map(
83+
(check, index) => (
84+
/* oxlint-disable react/no-array-index-key -- Check names can repeat; these status rows have no local state. */ <li
85+
key={`${index}:${check.name}`}
86+
className="col-span-full grid grid-cols-subgrid items-center text-xs"
87+
>
88+
<PullRequestCheckStatusIcon status={check.status} />
89+
<Tooltip>
90+
<TooltipTrigger render={<span className="min-w-0 truncate">{check.name}</span>} />
91+
<TooltipPopup side="top">{check.description ?? check.name}</TooltipPopup>
92+
</Tooltip>
93+
<span className="justify-self-end whitespace-nowrap text-muted-foreground">
94+
{pullRequestCheckStatusLabel(check)}
95+
</span>
96+
{check.url === null ? null : (
97+
<button
98+
type="button"
99+
className="text-primary hover:underline"
100+
onClick={() => {
101+
if (!check.url) return;
102+
void openLink(check.url).catch((error: unknown) => {
103+
console.error(error);
104+
toastManager.add({ type: "error", title: "Unable to open check details" });
105+
});
106+
}}
107+
>
108+
Details
109+
</button>
110+
)}
111+
</li>
112+
) /* oxlint-enable react/no-array-index-key */,
113+
)}
112114
</ul>
113115
</ScrollArea>
114116
{canCollapse ? (

0 commit comments

Comments
 (0)