





















@@ -30,6 +30,7 @@ const LOCALE_LABELS: Record<string, string> = {
3030"zh-CN": "Simplified Chinese",
3131"zh-TW": "Traditional Chinese",
3232};
33+const REPORT_LOCALES = new Set(Object.keys(LOCALE_LABELS));
3334const PATH_LABELS: Record<string, string> = {
3435"ui/src/ui/chat/chat-queue.ts": "Chat queue",
3536"ui/src/ui/chat/grouped-render.ts": "Chat message groups",
@@ -108,13 +109,16 @@ export function parseArgs(argv: string[]): ReportArgs {
108109continue;
109110}
110111if (arg === "--locale") {
111-args.locale = readOptionValue(argv, (index += 1), arg);
112+args.locale = parseLocale(readOptionValue(argv, (index += 1), arg));
112113continue;
113114}
114115if (arg === "--top") {
115116const raw = readOptionValue(argv, (index += 1), arg);
117+if (!/^[1-9][0-9]*$/.test(raw)) {
118+throw new Error(`--top must be a positive integer: ${raw}`);
119+}
116120const top = Number.parseInt(raw, 10);
117-if (!Number.isSafeInteger(top) || top < 1) {
121+if (!Number.isSafeInteger(top)) {
118122throw new Error(`--top must be a positive integer: ${raw}`);
119123}
120124args.top = top;
@@ -133,6 +137,13 @@ function readOptionValue(argv: string[], index: number, flag: string) {
133137return value;
134138}
135139140+function parseLocale(locale: string) {
141+if (!REPORT_LOCALES.has(locale)) {
142+throw new Error(`unknown locale: ${locale}`);
143+}
144+return locale;
145+}
146+136147export function filterRawCopyEntries(entries: RawCopyBaselineEntry[], surface?: string) {
137148if (!surface) {
138149return entries;
@@ -167,9 +178,13 @@ function compareCountThenName<T>(nameOf: (value: T) => string) {
167178}
168179169180function pathTokens(repoPath: string) {
170-return repoPath
171-.split("/")
172-.flatMap((part) => part.replace(/\.[^.]+$/, "").split(/[^A-Za-z0-9]+/))
181+return repoPath.split("/").flatMap((part) => surfaceTokens(part.replace(/\.[^.]+$/, "")));
182+}
183+184+function surfaceTokens(value: string) {
185+return value
186+.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
187+.split(/[^A-Za-z0-9]+/)
173188.filter(Boolean)
174189.map(normalizeToken);
175190}
@@ -206,7 +221,9 @@ export function filterTranslationKeysBySurface(keys: string[], surface?: string)
206221return keys;
207222}
208223const normalized = normalizeToken(surface);
209-return keys.filter((key) => key.split(".").some((part) => normalizeToken(part) === normalized));
224+return keys.filter((key) =>
225+key.split(".").some((part) => surfaceTokens(part).some((token) => token === normalized)),
226+);
210227}
211228212229export function formatReport(input: ReportInput) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。