mirror of
https://gitee.com/openharmony/interface_sdk-js
synced 2024-11-27 09:22:53 +00:00
!10595 api_check工具type Api适配typedef param returns throws
Merge pull request !10595 from fanjiaojiao/master
This commit is contained in:
commit
6474648b4e
@ -76,10 +76,15 @@ function checkReturnsValue(tag, node, fileName) {
|
||||
};
|
||||
const voidArr = ['void'];
|
||||
const tagValue = tag.type.replace(/\n|\r|\s/g, '');
|
||||
let apiReturnsValue = '';
|
||||
if (!commentNodeWhiteList.includes(node.kind)) {
|
||||
return returnsResult;
|
||||
}
|
||||
let apiReturnsValue = getDeclareValue(node.type);
|
||||
if (node.kind === ts.SyntaxKind.TypeAliasDeclaration) {
|
||||
apiReturnsValue = ts.SyntaxKind.VoidKeyword === node.type?.type ? 'void' : node.type?.type?.getText().replace(/\n|\r|\s/g, '');
|
||||
} else {
|
||||
apiReturnsValue = getDeclareValue(node.type);
|
||||
}
|
||||
if (voidArr.indexOf(apiReturnsValue) !== -1 || apiReturnsValue === undefined) {
|
||||
returnsResult.checkResult = false;
|
||||
returnsResult.errorInfo = ErrorValueInfo.ERROR_INFO_RETURNS;
|
||||
@ -404,8 +409,18 @@ function checkInterfaceTypedefTag(tag, node, fileName) {
|
||||
errorInfo: '',
|
||||
};
|
||||
const tagValue = tag.name;
|
||||
const tagType = tag.type.replace(/\n|\r|\s/g, '');
|
||||
|
||||
if (commentNodeWhiteList.includes(node.kind)) {
|
||||
const apiValue = node.name?.escapedText;
|
||||
if (node.kind === ts.SyntaxKind.TypeAliasDeclaration) {
|
||||
const isFunctionType = ts.SyntaxKind.FunctionType === node.type?.kind;
|
||||
let apiType = isFunctionType === true ? 'function' : node.type.getText().replace(/\n|\r|\s/g, '');
|
||||
if (tagType !== apiType) {
|
||||
interfaceResult.checkResult = false;
|
||||
interfaceResult.errorInfo = ErrorValueInfo.ERROR_INFO_VALUE_TYPEDEF;
|
||||
}
|
||||
} else {
|
||||
if (apiValue !== undefined && tagValue !== apiValue) {
|
||||
interfaceResult.checkResult = false;
|
||||
if (tag.tag === 'interface') {
|
||||
@ -415,6 +430,7 @@ function checkInterfaceTypedefTag(tag, node, fileName) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return interfaceResult;
|
||||
}
|
||||
exports.checkInterfaceTypedefTag = checkInterfaceTypedefTag;
|
||||
|
@ -54,7 +54,8 @@ function checkJsDocLegality(node, comments, checkInfoMap) {
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.ModuleDeclaration], ['namespace'], true, checkInfoMap);
|
||||
// 'param'
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor], ['param'], true, checkInfoMap,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor,
|
||||
ts.SyntaxKind.TypeAliasDeclaration], ['param'], true, checkInfoMap,
|
||||
(currentNode, checkResult) => {
|
||||
if (!new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.Constructor]).has(currentNode.kind)) {
|
||||
@ -65,14 +66,17 @@ function checkJsDocLegality(node, comments, checkInfoMap) {
|
||||
);
|
||||
// 'returns'
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature], ['returns'], true, checkInfoMap,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.TypeAliasDeclaration],
|
||||
['returns'], true, checkInfoMap,
|
||||
(currentNode, checkResult) => {
|
||||
if (!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) {
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature,
|
||||
ts.SyntaxKind.TypeAliasDeclaration]).has(currentNode.kind)) {
|
||||
return false;
|
||||
}
|
||||
return !(!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) && (currentNode.type &&
|
||||
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature,
|
||||
ts.SyntaxKind.TypeAliasDeclaration]).has(currentNode.kind)) && (currentNode.type &&
|
||||
currentNode.type.kind !== ts.SyntaxKind.VoidKeyword);
|
||||
}
|
||||
);
|
||||
@ -83,7 +87,8 @@ function checkJsDocLegality(node, comments, checkInfoMap) {
|
||||
}
|
||||
);
|
||||
// typedef/interface
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.InterfaceDeclaration], ['interface', 'typedef'], true, checkInfoMap);
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.InterfaceDeclaration, ts.SyntaxKind.TypeAliasDeclaration],
|
||||
['interface', 'typedef'], true, checkInfoMap);
|
||||
// 'type', 'readonly'
|
||||
legalityCheck(node, comments, [ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.PropertySignature],
|
||||
['type', 'readonly'], false, checkInfoMap);
|
||||
@ -138,12 +143,21 @@ function legalityCheck(node, comments, legalKinds, tagsName, isRequire, checkInf
|
||||
const illegalKinds = getIllegalKinds(legalKinds);
|
||||
let illegalKindSet = new Set(illegalKinds);
|
||||
const legalKindSet = new Set(legalKinds);
|
||||
const isFunctionType = ts.SyntaxKind.FunctionType === node.type?.kind;
|
||||
const functionTag = ['param', 'returns', 'throws'];
|
||||
tagsName.forEach(tagName => {
|
||||
if (tagName === 'extends') {
|
||||
illegalKindSet = new Set(commentNodeWhiteList);
|
||||
} else if (tagName === 'syscap') {
|
||||
illegalKindSet = new Set([]);
|
||||
}
|
||||
if (functionTag.includes(tagName) && !isFunctionType) {
|
||||
legalKindSet.delete(ts.SyntaxKind.TypeAliasDeclaration);
|
||||
}
|
||||
if (tagName === 'returns' && node.kind === ts.SyntaxKind.TypeAliasDeclaration && isFunctionType &&
|
||||
node.type?.type?.kind === ts.SyntaxKind.VoidKeyword) {
|
||||
legalKindSet.delete(ts.SyntaxKind.TypeAliasDeclaration);
|
||||
}
|
||||
comments.forEach((comment, index) => {
|
||||
if (!checkInfoMap[index]) {
|
||||
checkInfoMap[index] = {
|
||||
@ -156,8 +170,10 @@ function legalityCheck(node, comments, legalKinds, tagsName, isRequire, checkInf
|
||||
if (tagName === 'since') {
|
||||
}
|
||||
if (tagName === 'param' && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) ||
|
||||
ts.isFunctionDeclaration(node) || ts.isCallSignatureDeclaration(node) || ts.isConstructorDeclaration(node))) {
|
||||
parameterNum = node.parameters.length;
|
||||
ts.isFunctionDeclaration(node) || ts.isCallSignatureDeclaration(node) || ts.isConstructorDeclaration(node) ||
|
||||
ts.isTypeAliasDeclaration(node))) {
|
||||
const parameterLength = ts.isTypeAliasDeclaration(node) ? node.type.parameters?.length : node.parameters.length;
|
||||
parameterNum = parameterLength === undefined ? 0 : parameterLength;
|
||||
checkResult = parameterNum !== dealSpecialTagResult.paramTagNum;
|
||||
}
|
||||
let extraCheckResult = false;
|
||||
|
Loading…
Reference in New Issue
Block a user