错误么401描述校验,since值数值校验

Signed-off-by: fanjiaojiao0729 <fanjiaojiao@huawei.com>
This commit is contained in:
fanjiaojiao0729 2024-08-08 14:57:38 +08:00
parent 525830249b
commit 4aa2220cd2
5 changed files with 51 additions and 6 deletions

View File

@ -75,6 +75,10 @@
"API_DOC_SINCE_02": "JSDoc label order error, please adjust the order of [since] labels.",
"API_DOC_SINCE_03": "JSDoc tag validity verification failed. Please confirm if the [since] tag is missing.",
"API_DOC_SINCE_04": "The validity verification of the JSDoc tag failed. The [since] tag is not allowed to be reused, please delete the extra tags.",
"API_DOC_SINCE_05": "The [since] value is greater than the latest version number.",
"API_DOC_SINCE_06": "The [since] value for different jsdoc should not be the same.",
"API_DOC_SINCE_07": "The [since] value is greater than the latest version number.The [since] value for different jsdoc should not be the same.",
"API_DOC_SINCE_08": "The [since] tag value is incorrect. Please check if the tag value is a numerical value.The [since] value for different jsdoc should not be the same.",
"API_DOC_STAGEMODELONLY_01": "It was detected that there is an inheritable label [stagemodelonly] in the current file, but there are child nodes without this label.",
"API_DOC_STAGEMODELONLY_02": "JSDoc label order error, please adjust the order of [stagemodelonly] labels.",
"API_DOC_STAGEMODELONLY_03": "The validity verification of the JSDoc tag failed. The [stagemodelonly] tag is not allowed to be reused, please delete the extra tags.",
@ -103,6 +107,8 @@
"API_DOC_THROWS_07": "JSDoc label validity verification failed. The [throws 1] label is not allowed. Please check the label usage method.",
"API_DOC_THROWS_08": "The validity verification of the JSDoc tag failed. The [throws] tag is not allowed to be reused, please delete the extra tags.",
"API_DOC_THROWS_09": "The generic error code does not contain the current error code.",
"API_DOC_THROWS_10": "The description of the [1 throws] is incorrect. please fix it according to the specification.",
"API_DOC_THROWS_11": "The type of the [1] [throws] tag is incorrect. Please fill in [BusinessError].The description of the [1 throws] is incorrect. please fix it according to the specification.",
"API_DOC_TYPE_01": "The [type] tag type is incorrect. Please check if the type matches the attribute type.",
"API_DOC_TYPE_02": "JSDoc label order error, please adjust the order of [type] labels.",
"API_DOC_TYPE_03": "JSDoc label validity verification failed. The [type] label is not allowed. Please check the label usage method.",

View File

@ -1,3 +1,4 @@
{
"ApiCheckVersion": 12
"ApiCheckVersion": 12,
"ApiMaxVersion":13
}

View File

@ -15,12 +15,14 @@
import { ErrorTagFormat, ErrorMessage, PermissionData } from '../../../typedef/checker/result_type';
import { Comment } from '../../../typedef/parser/Comment';
import { CommonFunctions } from '../../../utils/checkUtils';
import { CommonFunctions, throwsTagDescriptionArr } from '../../../utils/checkUtils';
import { ApiInfo, ApiType, ClassInfo, GenericInfo, TypeAliasInfo, TypeAliasType, TypeParamInfo } from '../../../typedef/parser/ApiInfoDefination';
import { MethodInfo, PropertyInfo, ParamInfo } from '../../../typedef/parser/ApiInfoDefination';
import { PunctuationMark } from '../../../utils/Constant';
import { SystemCapability } from '../config/syscapConfigFile.json';
import { module } from '../config/permissionConfigFile.json';
import { toNumber } from 'lodash';
import { ApiMaxVersion } from '../config/api_check_version.json';
export class TagValueCheck {
/**
@ -47,7 +49,7 @@ export class TagValueCheck {
};
switch (tag.tag) {
case 'since':
errorTagInfo = TagValueCheck.sinceTagValueCheck(tag);
errorTagInfo = TagValueCheck.sinceTagValueCheck(singleApi, tag);
break;
case 'extends':
case 'implements':
@ -107,17 +109,28 @@ export class TagValueCheck {
* @param { Comment.CommentTag } tag
* @returns { ErrorTagFormat }
*/
static sinceTagValueCheck(tag: Comment.CommentTag): ErrorTagFormat {
static sinceTagValueCheck(singleApi: ApiInfo, tag: Comment.CommentTag): ErrorTagFormat {
const sinceValueCheckResult: ErrorTagFormat = {
state: true,
errorInfo: '',
};
const sinceValue: string = CommonFunctions.getSinceVersion(tag.name);
const sinceValueIsNumber: boolean = /^\d+$/.test(sinceValue);
const allSinceValue: string[] = [];
singleApi.getJsDocInfos().forEach((tagInfo: Comment.JsDocInfo) => {
allSinceValue.push(tagInfo.since);
});
const newSinceValueArr = Array.from(new Set(allSinceValue));
if (!sinceValueIsNumber) {
sinceValueCheckResult.state = false;
sinceValueCheckResult.errorInfo = ErrorMessage.ERROR_INFO_VALUE_SINCE;
} else if (toNumber(sinceValue) > toNumber(ApiMaxVersion)) {
sinceValueCheckResult.state = false;
sinceValueCheckResult.errorInfo = ErrorMessage.ERROR_INFO_VALUE_SINCE_NUMBER;
}
if (allSinceValue.length !== newSinceValueArr.length) {
sinceValueCheckResult.state = false;
sinceValueCheckResult.errorInfo = sinceValueCheckResult.errorInfo + ErrorMessage.ERROR_INFO_VALUE_SINCE_JSDOC;
}
return sinceValueCheckResult;
}
@ -392,11 +405,26 @@ export class TagValueCheck {
throwsValueCheckResult.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ERROR_INFO_VALUE1_THROWS, [
JSON.stringify(throwsIndex),
]);
} else if (!isNumber) {
}
if (!isNumber) {
throwsValueCheckResult.state = false;
throwsValueCheckResult.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ERROR_INFO_VALUE2_THROWS, [
JSON.stringify(throwsIndex),
]);
} else if (throwsTagName === '401') {
const specialThrowsDescription: string = tag.description;
const throws401DescriptionStartIndexof: number = specialThrowsDescription.indexOf(throwsTagDescriptionArr[0]);
const throws401DescriptionOneIndexof: number = specialThrowsDescription.indexOf(throwsTagDescriptionArr[1]);
const throws401DescriptionTwoIndexof: number = specialThrowsDescription.indexOf(throwsTagDescriptionArr[2]);
const throws401DescriptionThreeIndexof: number = specialThrowsDescription.indexOf(throwsTagDescriptionArr[3]);
const hasDescriptionContent: boolean = throws401DescriptionOneIndexof !== -1 || throws401DescriptionTwoIndexof !== -1 || throws401DescriptionThreeIndexof !== -1;
const descriptionReg = new RegExp(`${throwsTagDescriptionArr[0]}|${throwsTagDescriptionArr[1]}|${throwsTagDescriptionArr[2]}|${throwsTagDescriptionArr[3]}|<br>`, 'g');
const hasElseString: boolean = /[A-Za-z]+/.test(specialThrowsDescription.replace(descriptionReg, ''));
if (throws401DescriptionStartIndexof === -1 || throws401DescriptionStartIndexof > 1 || !hasDescriptionContent ||
hasElseString) {
throwsValueCheckResult.state = false;
throwsValueCheckResult.errorInfo = throwsValueCheckResult.errorInfo + ErrorMessage.ERROR_INFO_VALUE3_THROWS;
}
}
const allTagName: string[] = [];
tagsName?.forEach((tag: Comment.CommentTag) => {

View File

@ -101,6 +101,8 @@ export enum ErrorMessage {
ERROR_INFO_VALUE_IMPLEMENTS = 'The [implements] tag value is incorrect. Please check if the tag value matches the inherited class name.',
ERROR_INFO_VALUE_ENUM = 'The [enum] tag type is incorrect. Please check if the tag type is { string } or { number }.',
ERROR_INFO_VALUE_SINCE = 'The [since] tag value is incorrect. Please check if the tag value is a numerical value.',
ERROR_INFO_VALUE_SINCE_NUMBER = 'The [since] value is greater than the latest version number.',
ERROR_INFO_VALUE_SINCE_JSDOC = 'The [since] value for different jsdoc should not be the same.',
ERROR_INFO_RETURNS = 'The [returns] tag was used incorrectly. The returns tag should not be used when the return type is void.',
ERROR_INFO_VALUE_RETURNS = 'The [returns] tag type is incorrect. Please check if the tag type is consistent with the return type.',
ERROR_INFO_VALUE_USEINSTEAD = 'The [useinstead] tag value is incorrect. Please check the usage method.',
@ -117,6 +119,7 @@ export enum ErrorMessage {
ERROR_INFO_VALUE_PARAM = 'The value of the [$$] [param] tag is incorrect. Please check if it matches the [$$] parameter name.',
ERROR_INFO_VALUE1_THROWS = 'The type of the [$$] [throws] tag is incorrect. Please fill in [BusinessError].',
ERROR_INFO_VALUE2_THROWS = 'The type of the [$$] [throws] tag is incorrect. Please check if the tag value is a numerical value.',
ERROR_INFO_VALUE3_THROWS = 'The description of the [401 throws] is incorrect. please fix it according to the specification.',
ERROR_INFO_INHERIT = 'It was detected that there is an inheritable label [$$] in the current file, but there are child nodes without this label.',
ERROR_INFO_FOLLOW = 'It was detected that there is a following label [$$] in the current file, but the parent nodes without this label.',
ERROR_ORDER = 'JSDoc label order error, please adjust the order of [$$] labels.',

View File

@ -409,3 +409,10 @@ export const apiCheckResult: ApiResultMessage[] = [];
export const punctuationMarkSet: Set<string> = new Set(['\\{', '\\}', '\\(', '\\)', '\\[', '\\]', '\\@', '\\.', '\\:',
'\\,', '\\;', '\\(', '\\)', '\\"', '\\/', '\\_', '\\-', '\\=', '\\?', '\\<', '\\>', '\\,', '\\!', '\\#', '\', '\',
'\\:', '\\|', '\\%', '\\&', '\\¡', '\\¢', '\\+', '\\`', '\\\\', '\\\'']);
export const throwsTagDescriptionArr: string[] = [
'Parameter error. Possible causes:',
'Mandatory parameters are left unspecified',
'Incorrect parameter types',
'Parameter verification failed'
];