From e9165ead186cb1807714b306a4719fb0884b6238 Mon Sep 17 00:00:00 2001 From: HIsheR Date: Fri, 23 Oct 2026 15:32:53 +0800 Subject: [PATCH] =?UTF-8?q?iter:=20b01=20=E5=89=8D=E7=BD=AE=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E2=80=94=E2=80=94style=20=E6=A3=80=E6=9F=A5=E5=85=88?= =?UTF-8?q?=E5=89=A5=E7=A6=BB=E5=AD=97=E9=9D=A2=E9=87=8F=EF=BC=8C=E6=B6=88?= =?UTF-8?q?=E9=99=A4=20URL=20=E4=B8=AD=20//=20=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tools/cli/bin/ua.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/tools/cli/bin/ua.js b/packages/tools/cli/bin/ua.js index cc6233f..100f2bc 100644 --- a/packages/tools/cli/bin/ua.js +++ b/packages/tools/cli/bin/ua.js @@ -491,6 +491,11 @@ function collectSourceFiles() { return out; } +/*** 把字符串 / 模板字面量整体替换为等长空格,便于按位置定位真实注释(避开 URL、正则里的 //) ***/ +function blankStrings(line) { + return line.replace(/(['"`])(?:\\.|(?!\1)[^\\])*\1/g, (m) => ' '.repeat(m.length)); +} + /*** 检查单文件:导出缺注释块、接口字段缺行尾注释、行注释非中文 ***/ function styleCheckFile(file, src) { const issues = []; @@ -528,7 +533,7 @@ function styleCheckFile(file, src) { } } - const hash = raw.indexOf('//'); + const hash = blankStrings(raw).indexOf('//'); // 注释定位:先剥离字面量,'https://' 不算注释 if (hash >= 0) { const text = raw.slice(hash + 2); const isPragma = /^[\s*/]*(eslint|@ts-|prettier-ignore|istanbul|c8|node:)/i.test(text);