Skip to content

Commit 6d97421

Browse files
committed
fix: address remaining review comments
- complete.ts: Build nameMap first, pass [...nameMap.keys()] to fuzzyMatch — eliminates the separate slugs array - completions.ts: Revert extractSubcommands to for-of loop (more efficient than filter.map for small arrays) - completions.ts: s/whitelist/allowlist in shellVarName JSDoc
1 parent 06c1c9c commit 6d97421

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/lib/complete.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ export async function completeOrgSlugs(
155155
return [];
156156
}
157157

158-
const slugs = orgs.map((o) => o.slug);
159-
const matched = fuzzyMatch(partial, slugs);
160-
161158
const nameMap = new Map(orgs.map((o) => [o.slug, o.name]));
159+
const matched = fuzzyMatch(partial, [...nameMap.keys()]);
160+
162161
return matched.map((slug) => ({
163162
value: `${slug}${suffix}`,
164163
description: nameMap.get(slug),

src/lib/completions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ function extractSubcommands(routeMap: {
113113
hidden: boolean;
114114
}[];
115115
}): CommandEntry[] {
116-
return routeMap
117-
.getAllEntries()
118-
.filter((sub) => !sub.hidden)
119-
.map((sub) => buildCommandEntry(sub.name.original, sub.target));
116+
const subcommands: CommandEntry[] = [];
117+
for (const sub of routeMap.getAllEntries()) {
118+
if (!sub.hidden) {
119+
subcommands.push(buildCommandEntry(sub.name.original, sub.target));
120+
}
121+
}
122+
return subcommands;
120123
}
121124

122125
/**
@@ -154,7 +157,7 @@ export function extractCommandTree(): CommandTree {
154157
/**
155158
* Sanitize a string for use in a shell variable name.
156159
*
157-
* Uses a whitelist approach — replaces any character that is not a valid
160+
* Uses an allowlist approach — replaces any character that is not a valid
158161
* shell identifier character (`[a-zA-Z0-9_]`) with an underscore.
159162
* Input comes from Stricli route/flag names (alphanumeric + hyphen),
160163
* but the whitelist guards against unexpected characters.

0 commit comments

Comments
 (0)