mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
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:
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user