From 36e18f935d9abb497db6b96ce018370dec1bf8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Sun, 23 Aug 2026 04:32:06 +0000 Subject: [PATCH] scanner: do not count commented-out code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Header.tsx has a disabled dev-console button inside a JSX comment and IntegrationsSettings has a commented-out section literal. Four hits in officer-web, all of them code nobody ships — and an area cannot reach zero while a comment counts against it. Only two shapes stripped, both unambiguous: block comments, and lines whose first non-space characters are //. Stripping every // would eat the tail of any string holding a URL. Verified the delta is exactly those four. --- scripts/i18n/scan-hardcoded.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/i18n/scan-hardcoded.ts b/scripts/i18n/scan-hardcoded.ts index b4139935..6aec3f89 100755 --- a/scripts/i18n/scan-hardcoded.ts +++ b/scripts/i18n/scan-hardcoded.ts @@ -94,6 +94,16 @@ function isHuman(value: string | undefined): value is string { return true; } +/** + * Commented-out code is not user-facing text. `Header.tsx` carries a disabled dev-console button inside + * a `{/* … *\/}` block, and counting it means the area can never reach zero without editing a comment. + * + * Deliberately only two shapes, both unambiguous: a block comment, and a line whose first non-space + * characters are `//`. Stripping every `//` would eat the tail of any string holding a URL. + */ +const stripComments = (source: string): string => + source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^[ \t]*\/\/.*$/gm, ''); + function* walk(dir: string): Generator { let entries: string[]; try { @@ -125,7 +135,7 @@ function scan(root: string): { files: number; hits: Hit[] } { files++; let source: string; try { - source = readFileSync(file, 'utf8'); + source = stripComments(readFileSync(file, 'utf8')); } catch { continue; }