iter: b01 前置修复——style 检查先剥离字面量,消除 URL 中 // 误判

This commit is contained in:
HIsheR
2026-10-23 15:32:53 +08:00
parent 17a4fb171b
commit e9165ead18
+6 -1
View File
@@ -491,6 +491,11 @@ function collectSourceFiles() {
return out; return out;
} }
/*** 把字符串 / 模板字面量整体替换为等长空格,便于按位置定位真实注释(避开 URL、正则里的 //) ***/
function blankStrings(line) {
return line.replace(/(['"`])(?:\\.|(?!\1)[^\\])*\1/g, (m) => ' '.repeat(m.length));
}
/*** 检查单文件:导出缺注释块、接口字段缺行尾注释、行注释非中文 ***/ /*** 检查单文件:导出缺注释块、接口字段缺行尾注释、行注释非中文 ***/
function styleCheckFile(file, src) { function styleCheckFile(file, src) {
const issues = []; const issues = [];
@@ -528,7 +533,7 @@ function styleCheckFile(file, src) {
} }
} }
const hash = raw.indexOf('//'); const hash = blankStrings(raw).indexOf('//'); // 注释定位:先剥离字面量,'https://' 不算注释
if (hash >= 0) { if (hash >= 0) {
const text = raw.slice(hash + 2); const text = raw.slice(hash + 2);
const isPragma = /^[\s*/]*(eslint|@ts-|prettier-ignore|istanbul|c8|node:)/i.test(text); const isPragma = /^[\s*/]*(eslint|@ts-|prettier-ignore|istanbul|c8|node:)/i.test(text);