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