bugfix: interface合法性检查错误、useinstead值检查错误、构造函数无法使用param标签

Signed-off-by: yangbo_404 <yangbo198@huawei.com>
Change-Id: I001ab1edc230e1bf7fb0fa46cd95f0cc09129abd
This commit is contained in:
yangbo_404 2023-03-17 08:34:40 +00:00
parent 7dd019b886
commit 48556e6d8d
3 changed files with 14 additions and 10 deletions

View File

@ -187,9 +187,9 @@ function isArkUIApiFile(fileName) {
* xxx.xxx#event:xxx * xxx.xxx#event:xxx
*/ */
function checkModule(moduleValue) { function checkModule(moduleValue) {
return /^[A-Za-z]+\b(\.[A-Za-z]+\b)*$/.test(moduleValue) || return /^[A-Za-z_]+\b(\.[A-Za-z_]+\b)*$/.test(moduleValue) ||
/^[A-Za-z]+\b(\.[A-Za-z]+\b)*\#[A-Za-z]+\b$/.test(moduleValue) || /^[A-Za-z_]+\b(\.[A-Za-z_]+\b)*\#[A-Za-z_]+\b$/.test(moduleValue) ||
/^[A-Za-z]+\b(\.[A-Za-z]+\b)*\#event:[A-Za-z]+\b$/.test(moduleValue); /^[A-Za-z_]+\b(\.[A-Za-z_]+\b)*\#event:[A-Za-z_]+\b$/.test(moduleValue);
} }
function splitUseinsteadValue(useinsteadValue) { function splitUseinsteadValue(useinsteadValue) {
@ -212,14 +212,14 @@ function splitUseinsteadValue(useinsteadValue) {
const fileNameArray = splitArray[0].split('.'); const fileNameArray = splitArray[0].split('.');
if (fileNameArray.length === 1) { if (fileNameArray.length === 1) {
// arkui // arkui
if (!/^[A-Za-z]+\b$/.test(fileNameArray[0]) || !checkModule(splitArray[1])) { if (!/^[A-Za-z_]+\b$/.test(fileNameArray[0]) || !checkModule(splitArray[1])) {
splitResult.checkResult = false; splitResult.checkResult = false;
} }
} else { } else {
// 非arkui // 非arkui
let checkFileName = true; let checkFileName = true;
for (let i = 0; i < fileNameArray.length; i++) { for (let i = 0; i < fileNameArray.length; i++) {
if (fileNameArray[0] !== 'ohos' || !/^[A-Za-z]+\b$/.test(fileNameArray[i])) { if (fileNameArray[0] !== 'ohos' || !/^[A-Za-z_]+\b$/.test(fileNameArray[i])) {
checkFileName = false; checkFileName = false;
} }
} }

View File

@ -69,10 +69,10 @@ function checkJsDocLegality(node, sourcefile, checkInfoMap) {
); );
// 'param' // 'param'
legalityCheck(node, sourcefile, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, legalityCheck(node, sourcefile, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature], ['param'], true, checkInfoMap, ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor], ['param'], true, checkInfoMap,
(currentNode, checkResult) => { (currentNode, checkResult) => {
if (!new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, if (!new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration]).has(currentNode.kind)) { ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.Constructor]).has(currentNode.kind)) {
return true; return true;
} }
return currentNode.parameters && currentNode.parameters.length > 0; return currentNode.parameters && currentNode.parameters.length > 0;
@ -155,6 +155,8 @@ function legalityCheck(node, sourcefile, legalKinds, tagsName, isRequire, checkI
} else if (tag.tag === 'deprecated') { } else if (tag.tag === 'deprecated') {
useinsteadResultObj.hasDeprecated = true; useinsteadResultObj.hasDeprecated = true;
} }
} else if ((tagName === 'interface' || tagName === 'typedef') && (tag.tag === 'interface' || tag.tag === 'typedef')) {
checkResult = true;
} else if (tag.tag === tagName) { } else if (tag.tag === tagName) {
checkResult = true; checkResult = true;
} }
@ -163,7 +165,7 @@ function legalityCheck(node, sourcefile, legalKinds, tagsName, isRequire, checkI
} }
}); });
if (tagName === 'param' && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || if (tagName === 'param' && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) ||
ts.isFunctionDeclaration(node) || ts.isCallSignatureDeclaration(node))) { ts.isFunctionDeclaration(node) || ts.isCallSignatureDeclaration(node) || ts.isConstructorDeclaration(node))) {
parameterNum = node.parameters.length; parameterNum = node.parameters.length;
checkResult = parameterNum !== paramTagNum; checkResult = parameterNum !== paramTagNum;
} }
@ -251,7 +253,8 @@ function checkJsDocOfCurrentNode(node, sourcefile, permissionConfigPath, fileNam
const checker = JsDocValueChecker[tag.tag]; const checker = JsDocValueChecker[tag.tag];
if (checker) { if (checker) {
let valueCheckResult; let valueCheckResult;
if (tag.tag === 'param') { if (tag.tag === 'param' && [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor].indexOf(node.kind) >= 0) {
valueCheckResult = checker(tag, node, sourcefile, fileName, paramIndex++); valueCheckResult = checker(tag, node, sourcefile, fileName, paramIndex++);
} else if (tag.tag === 'throws') { } else if (tag.tag === 'throws') {
valueCheckResult = checker(tag, node, sourcefile, fileName, throwsIndex++); valueCheckResult = checker(tag, node, sourcefile, fileName, throwsIndex++);

View File

@ -282,7 +282,8 @@ class JSDocModificationManager {
static addParamTag(node: comment.CommentNode, commentInfo: comment.CommentInfo, tagName: string, static addParamTag(node: comment.CommentNode, commentInfo: comment.CommentInfo, tagName: string,
context: Context | undefined): boolean { context: Context | undefined): boolean {
if (node.astNode && (ts.isMethodDeclaration(node.astNode) || ts.isMethodSignature(node.astNode) || if (node.astNode && (ts.isMethodDeclaration(node.astNode) || ts.isMethodSignature(node.astNode) ||
ts.isFunctionDeclaration(node.astNode) || ts.isCallSignatureDeclaration(node.astNode))) { ts.isFunctionDeclaration(node.astNode) || ts.isCallSignatureDeclaration(node.astNode) ||
ts.isConstructorDeclaration(node.astNode))) {
let paramTagNum: number = 0; let paramTagNum: number = 0;
commentInfo.commentTags.forEach((tag: comment.CommentTag) => { commentInfo.commentTags.forEach((tag: comment.CommentTag) => {
if (tag.tag === 'param') { if (tag.tag === 'param') {