Skip to content

Commit a23c466

Browse files
committed
refactor: remove redundant indexed access fallbacks
1 parent 7eaa83a commit a23c466

21 files changed

Lines changed: 59 additions & 110 deletions

src/cli.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ function hasExplicitMetroRuntimeOverrides(explicitFlagKeys: Set<FlagKey>): boole
480480

481481
function guessSessionFromArgv(argv: string[]): string | null {
482482
for (let i = 0; i < argv.length; i += 1) {
483-
const token = argv[i];
484-
if (token === undefined) continue;
483+
const token = argv[i]!;
485484
if (token.startsWith('--session=')) {
486485
const inline = token.slice('--session='.length).trim();
487486
return inline.length > 0 ? inline : null;

src/command-codecs/targets.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ export function readFillTargetFromPositionals(positionals: string[]): DecodedFil
6969
kind: 'ref',
7070
target: {
7171
ref,
72-
label:
73-
positionals.length >= 3 && maybeLabel !== undefined
74-
? optionalTrimmedText([maybeLabel])
75-
: undefined,
72+
label: positionals.length >= 3 ? optionalTrimmedText([maybeLabel!]) : undefined,
7673
},
7774
text,
7875
};

src/command-codecs/wait.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export function waitOptionsToPositionals(options: WaitCommandOptions): string[]
6767

6868
export function parseWaitPositionals(args: string[]): WaitParsed | null {
6969
if (args.length === 0) return null;
70-
const firstArg = args[0];
71-
if (firstArg === undefined) return null;
70+
const firstArg = args[0]!;
7271

7372
const sleepMs = parseTimeout(firstArg);
7473
if (sleepMs !== null) return { kind: 'sleep', durationMs: sleepMs };

src/commands/interaction-targeting.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ function findPreferredActionableDescendant(
8080
if (sameRectChildren.length !== 1) {
8181
break;
8282
}
83-
const next = sameRectChildren[0];
84-
if (next === undefined) break;
85-
current = next;
83+
current = sameRectChildren[0]!;
8684
}
8785

8886
return current === node ? null : current;

src/commands/react-native/overlay.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,15 @@ function actionFromDismissNode(node: SnapshotNode): ReactNativeOverlayDismissTar
177177
function chooseCollapsedWarningNode(nodes: SnapshotNode[]): SnapshotNode | null {
178178
const withRect = nodes.filter((node) => node.rect);
179179
if (withRect.length === 0) return null;
180-
return (
181-
withRect.sort((a, b) => {
182-
const aHittable = a.hittable === true ? 1 : 0;
183-
const bHittable = b.hittable === true ? 1 : 0;
184-
if (aHittable !== bHittable) return bHittable - aHittable;
185-
const aWidth = a.rect?.width ?? 0;
186-
const bWidth = b.rect?.width ?? 0;
187-
if (aWidth !== bWidth) return bWidth - aWidth;
188-
return (b.rect?.y ?? 0) - (a.rect?.y ?? 0);
189-
})[0] ?? null
190-
);
180+
return withRect.sort((a, b) => {
181+
const aHittable = a.hittable === true ? 1 : 0;
182+
const bHittable = b.hittable === true ? 1 : 0;
183+
if (aHittable !== bHittable) return bHittable - aHittable;
184+
const aWidth = a.rect?.width ?? 0;
185+
const bWidth = b.rect?.width ?? 0;
186+
if (aWidth !== bWidth) return bWidth - aWidth;
187+
return (b.rect?.y ?? 0) - (a.rect?.y ?? 0);
188+
})[0]!;
191189
}
192190

193191
function collapsedBannerClosePoint(node: SnapshotNode): Point {

src/core/dispatch-series.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export function shouldUseIosDragSeries(device: DeviceInfo, count: number): boole
3434

3535
export function computeDeterministicJitter(index: number, jitterPx: number): [number, number] {
3636
if (jitterPx <= 0) return [0, 0];
37-
const [dx, dy] = DETERMINISTIC_JITTER_PATTERN[index % DETERMINISTIC_JITTER_PATTERN.length] ?? [
38-
0, 0,
39-
];
37+
const [dx, dy] = DETERMINISTIC_JITTER_PATTERN[index % DETERMINISTIC_JITTER_PATTERN.length]!;
4038
return [dx * jitterPx, dy * jitterPx];
4139
}
4240

src/daemon/artifact-archive.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ function resolveArchiveRootName(entries: string[], platform: 'ios' | 'android'):
9292
const rootEntries = [...roots];
9393
if (platform === 'ios') {
9494
const appRoots = rootEntries.filter((entry) => entry.toLowerCase().endsWith('.app'));
95-
const appRoot = appRoots[0];
96-
if (appRoots.length === 1 && appRoot !== undefined) return appRoot;
95+
if (appRoots.length === 1) return appRoots[0]!;
9796
if (appRoots.length === 0) {
9897
throw new AppError(
9998
'INVALID_ARGS',
@@ -105,8 +104,7 @@ function resolveArchiveRootName(entries: string[], platform: 'ios' | 'android'):
105104
`iOS app bundle archives must contain exactly one top-level .app directory, found: ${appRoots.join(', ')}`,
106105
);
107106
}
108-
const rootEntry = rootEntries[0];
109-
if (rootEntries.length === 1 && rootEntry !== undefined) return rootEntry;
107+
if (rootEntries.length === 1) return rootEntries[0]!;
110108
throw new AppError(
111109
'INVALID_ARGS',
112110
`Archive must contain a single top-level bundle, found: ${rootEntries.join(', ')}`,

src/daemon/handlers/find.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ export async function handleFindCommands(params: {
140140

141141
if (requiresRect && bestMatches.matches.length > 1) {
142142
if (req.flags?.findFirst) {
143-
const firstMatch = bestMatches.matches[0];
144-
if (firstMatch !== undefined) bestMatches.matches = [firstMatch];
143+
bestMatches.matches = [bestMatches.matches[0]!];
145144
} else if (req.flags?.findLast) {
146-
const lastMatch = bestMatches.matches.at(-1);
147-
if (lastMatch !== undefined) bestMatches.matches = [lastMatch];
145+
bestMatches.matches = [bestMatches.matches[bestMatches.matches.length - 1]!];
148146
} else {
149147
return buildAmbiguousMatchError(bestMatches.matches, locator, query);
150148
}

src/daemon/session-routing.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export function resolveEffectiveSessionName(
1212
if (sessionStore.has(requested)) return requested;
1313

1414
const sessions = sessionStore.toArray();
15-
const onlySession = sessions[0];
16-
if (sessions.length === 1 && onlySession !== undefined) return onlySession.name;
15+
if (sessions.length === 1) return sessions[0]!.name;
1716
return requested;
1817
}
1918

src/platforms/android/app-lifecycle.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ export async function resolveAndroidApp(
6868
const matches = packages.filter((pkg: string) =>
6969
pkg.toLowerCase().includes(trimmed.toLowerCase()),
7070
);
71-
const match = matches[0];
72-
if (matches.length === 1 && match !== undefined) {
71+
if (matches.length === 1) {
7372
return androidAppResolutionCache.set(cacheScope, trimmed, {
7473
type: 'package',
75-
value: match,
74+
value: matches[0]!,
7675
});
7776
}
7877

@@ -424,10 +423,9 @@ export function parseAndroidLaunchComponent(stdout: string): string | null {
424423
.map((line: string) => line.trim())
425424
.filter(Boolean);
426425
for (let index = lines.length - 1; index >= 0; index -= 1) {
427-
const line = lines[index];
428-
if (line === undefined) continue;
426+
const line = lines[index]!;
429427
if (!line.includes('/')) continue;
430-
return line.split(/\s+/)[0] ?? null;
428+
return line.split(/\s+/)[0]!;
431429
}
432430
return null;
433431
}

0 commit comments

Comments
 (0)