chore(lint): prefer-array-find over filter().at/pop

Replace filter(pred).at(-1)/pop() patterns with findLast(pred) and
filter(pred)[0] with find(pred) across server and app.
This commit is contained in:
Mohamed Boudra
2026-04-24 07:06:22 +07:00
parent 39ee113691
commit aceb399505
13 changed files with 16 additions and 22 deletions

View File

@@ -314,7 +314,7 @@ export const setWorkingDirectory = async (page: Page, directory: string) => {
if (trimmedDirectory.startsWith("/private/var/")) {
directoryCandidates.add(trimmedDirectory.replace(/^\/private/, ""));
}
const basename = trimmedDirectory.split("/").filter(Boolean).pop() ?? trimmedDirectory;
const basename = trimmedDirectory.split("/").findLast(Boolean) ?? trimmedDirectory;
await expect
.poll(

View File

@@ -570,8 +570,7 @@ export async function installTerminalKeystrokeStressProbe(page: Page): Promise<v
lastXtermCommitAt:
this.xtermWrites
.map((write) => write.committedAt)
.filter((at): at is number => typeof at === "number")
.at(-1) ?? null,
.findLast((at): at is number => typeof at === "number") ?? null,
};
},
};

View File

@@ -116,7 +116,7 @@ export async function seedProjectForWorkspaceSetup(
}
export function projectNameFromPath(repoPath: string): string {
return repoPath.replace(/\/+$/, "").split("/").filter(Boolean).pop() ?? repoPath;
return repoPath.replace(/\/+$/, "").split("/").findLast(Boolean) ?? repoPath;
}
export async function openHomeWithProject(page: Page, repoPath: string): Promise<void> {

View File

@@ -242,7 +242,7 @@ export function WorkspaceSetupDialog() {
workspace?.name ||
workspace?.projectDisplayName ||
displayName ||
sourceDirectory.split(/[\\/]/).filter(Boolean).pop() ||
sourceDirectory.split(/[\\/]/).findLast(Boolean) ||
sourceDirectory;
const placeholderLabel = projectIconPlaceholderLabelFromDisplayName(workspaceTitle);

View File

@@ -14,7 +14,7 @@ const CENTERED_PADDED_STYLE = {
} as const;
function useFilePanelDescriptor(target: { kind: "file"; path: string }) {
const fileName = target.path.split("/").filter(Boolean).pop() ?? target.path;
const fileName = target.path.split("/").findLast(Boolean) ?? target.path;
return {
label: fileName,
subtitle: target.path,

View File

@@ -457,7 +457,7 @@ export function NewWorkspaceScreen({
workspace?.name ||
workspace?.projectDisplayName ||
displayName ||
sourceDirectory.split(/[\\/]/).filter(Boolean).pop() ||
sourceDirectory.split(/[\\/]/).findLast(Boolean) ||
sourceDirectory;
const addImagesRef = useRef<((images: ImageAttachment[]) => void) | null>(null);

View File

@@ -161,7 +161,7 @@ function getFallbackTabLabel(tab: WorkspaceTabDescriptor): string {
return "Terminal";
}
if (tab.target.kind === "file") {
return tab.target.path.split("/").filter(Boolean).pop() ?? tab.target.path;
return tab.target.path.split("/").findLast(Boolean) ?? tab.target.path;
}
return "Agent";
}

View File

@@ -171,7 +171,7 @@ function getFallbackTabOptionLabel(tab: WorkspaceTabDescriptor): string {
return "Terminal";
}
if (tab.target.kind === "file") {
return tab.target.path.split("/").filter(Boolean).pop() ?? tab.target.path;
return tab.target.path.split("/").findLast(Boolean) ?? tab.target.path;
}
return "Agent";
}

View File

@@ -352,9 +352,7 @@ export async function generateStructuredAgentResponse<T>(
return result.finalText;
}
// Fallback for providers that may not populate finalText consistently.
const lastAssistant = result.timeline
.filter((item) => item.type === "assistant_message")
.at(-1);
const lastAssistant = result.timeline.findLast((item) => item.type === "assistant_message");
return lastAssistant?.text ?? "";
};
return await getStructuredAgentResponse({

View File

@@ -43,7 +43,7 @@ describe("TTSManager", () => {
const audioMsgs = emitted.filter((m) => m.type === "audio_output");
expect(audioMsgs).toHaveLength(1);
const [audioMessage] = emitted.filter(isAudioOutputMessage);
const audioMessage = emitted.find(isAudioOutputMessage);
expect(audioMessage).toBeDefined();
expect(audioMessage?.payload.groupId).toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,

View File

@@ -28,9 +28,9 @@ function lastUpsertFor(
updates: AgentUpdatePayload[],
agentId: string,
): AgentUpsertPayload | undefined {
return updates
.filter((u): u is AgentUpsertPayload => u.kind === "upsert" && u.agent.id === agentId)
.at(-1);
return updates.findLast(
(u): u is AgentUpsertPayload => u.kind === "upsert" && u.agent.id === agentId,
);
}
describe("mode-switch update propagation", () => {

View File

@@ -532,9 +532,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
): Promise<WorkspaceGitMetadata> {
const snapshot = await this.getSnapshot(cwd, options);
const directoryName =
options?.directoryName ??
normalizeWorkspaceId(cwd).split(/[\\/]/).filter(Boolean).at(-1) ??
cwd;
options?.directoryName ?? normalizeWorkspaceId(cwd).split(/[\\/]/).findLast(Boolean) ?? cwd;
return buildWorkspaceGitMetadataFromSnapshot({
cwd: normalizeWorkspaceId(cwd),
directoryName,

View File

@@ -179,8 +179,7 @@ export class WorkspaceReconciliationService {
siblings: PersistedWorkspaceRecord[],
changes: ReconciliationChange[],
): Promise<void> {
const directoryName =
project.rootPath.split(/[\\/]/).filter(Boolean).at(-1) ?? project.rootPath;
const directoryName = project.rootPath.split(/[\\/]/).findLast(Boolean) ?? project.rootPath;
const currentGit = await this.readWorkspaceGitMetadata(project.rootPath, directoryName);
const projectUpdates: Partial<
@@ -220,7 +219,7 @@ export class WorkspaceReconciliationService {
const existingSiblings = siblings.filter((workspace) => existsSync(workspace.cwd));
await Promise.all(
existingSiblings.map(async (workspace) => {
const wsDirName = workspace.cwd.split(/[\\/]/).filter(Boolean).at(-1) ?? workspace.cwd;
const wsDirName = workspace.cwd.split(/[\\/]/).findLast(Boolean) ?? workspace.cwd;
const wsGit = await this.readWorkspaceGitMetadata(workspace.cwd, wsDirName);
if (wsGit.projectKind === "git" && workspace.displayName !== wsGit.workspaceDisplayName) {