fix: 修复忽略的一处bug

This commit is contained in:
Pan Qiancheng 2026-01-12 16:28:07 +08:00
parent e4b5593c06
commit 68542b3120
2 changed files with 30 additions and 18 deletions

View File

@ -685,14 +685,21 @@ function performCustomChecks(pwd, program, typeChecker, customConfig) {
if (ignoreCommentNodes.has(node)) {
return true;
}
// 如果文件开头有忽略注释,整个文件都忽略
// 如果文件开头有忽略注释,整个文件都忽略(严格匹配)
const fileStartComments = ts.getLeadingCommentRanges(sourceFile.getFullText(), 0);
if (fileStartComments) {
for (const comment of fileStartComments) {
const commentText = sourceFile.getFullText().substring(comment.pos, comment.end);
if (isIgnoreComment(commentText)) {
return true;
}
if (fileStartComments && fileStartComments.length > 0) {
// 只检查第一个注释块
const firstComment = fileStartComments[0];
const commentText = sourceFile.getFullText().substring(firstComment.pos, firstComment.end).trim();
// 严格匹配:注释必须单独包含忽略标签,不能是其他内容的一部分
const isFileIgnore = exports.OAK_IGNORE_TAGS.some(tag => {
// 匹配 // @oak-ignore 或 /* @oak-ignore */ 格式
const singleLinePattern = new RegExp(`^//\\s*${tag.replace('@', '\\@')}\\s*$`);
const multiLinePattern = new RegExp(`^/\\*\\s*${tag.replace('@', '\\@')}\\s*\\*/$`);
return singleLinePattern.test(commentText) || multiLinePattern.test(commentText);
});
if (isFileIgnore) {
return true;
}
}
// 向上查找父节点最多3层

View File

@ -878,18 +878,23 @@ export function performCustomChecks(
return true;
}
// 如果文件开头有忽略注释,整个文件都忽略
const fileStartComments = ts.getLeadingCommentRanges(
sourceFile.getFullText(),
0
);
// 如果文件开头有忽略注释,整个文件都忽略(严格匹配)
const fileStartComments = ts.getLeadingCommentRanges(sourceFile.getFullText(), 0);
if (fileStartComments && fileStartComments.length > 0) {
// 只检查第一个注释块
const firstComment = fileStartComments[0];
const commentText = sourceFile.getFullText().substring(firstComment.pos, firstComment.end).trim();
if (fileStartComments) {
for (const comment of fileStartComments) {
const commentText = sourceFile.getFullText().substring(comment.pos, comment.end);
if (isIgnoreComment(commentText)) {
return true;
}
// 严格匹配:注释必须单独包含忽略标签,不能是其他内容的一部分
const isFileIgnore = OAK_IGNORE_TAGS.some(tag => {
// 匹配 // @oak-ignore 或 /* @oak-ignore */ 格式
const singleLinePattern = new RegExp(`^//\\s*${tag.replace('@', '\\@')}\\s*$`);
const multiLinePattern = new RegExp(`^/\\*\\s*${tag.replace('@', '\\@')}\\s*\\*/$`);
return singleLinePattern.test(commentText) || multiLinePattern.test(commentText);
});
if (isFileIgnore) {
return true;
}
}