error_code 检查

This commit is contained in:
huawei 2024-06-08 11:18:42 +08:00
parent 1cd7140dd2
commit 1e3b877fb7
4 changed files with 58 additions and 4 deletions

View File

@ -116,7 +116,8 @@
"API_DOC_GLOBAL_02": "JSDoc tag validity verification failed. Please confirm if the [kit] tag is missing.",
"API_DOC_JSDOC_01": "Jsdoc needs to be added to the current API.",
"API_DOC_JSDOC_02": "JSDoc tag validity verification failed. Please confirm if the [since] tag is missing.JSDoc tag validity verification failed. Please confirm if the [syscap] tag is missing.",
"API_DOC_JSDOC_03": "JSDoc has chinese."
"API_DOC_JSDOC_03": "JSDoc has chinese.",
"API_ERROR_ERROR_CODE": "The generic error code does not contain the current error code."
},
"DEFINE": {
"API_DEFINE_UNALLOWABLE_01": "Illegal [any] keyword used in the API.",

View File

@ -42,6 +42,7 @@ import { EventMethodData } from '../../../typedef/checker/event_method_check_int
import { ApiChangeCheck } from './check_api_diff';
import { TagInheritCheck } from './tag_inherit_check';
import { ChineseCheck } from "./check_chinese";
import {CheckErrorCode} from "./check_error_code";
export class Check {
/**
@ -130,6 +131,8 @@ export class Check {
const namingCheckResult: ErrorTagFormat = ApiNamingCheck.namingCheck(singleApi);
// check jsdoc chinese
const chineseCheckResult: ErrorTagFormat = ChineseCheck.checkChinese(apiJsdoc);
// check error code
const errorCodeResult: ErrorTagFormat = CheckErrorCode.checkErrorCode(apiJsdoc);
// tags name check
const tagNamseCheckResult: ErrorTagFormat = TagNameCheck.tagNameCheck(apiJsdoc);
// tags inherit check
@ -222,6 +225,22 @@ export class Check {
compositiveLocalResult
);
}
if (!errorCodeResult.state) {
AddErrorLogs.addAPICheckErrorLogs(
ErrorID.ERROR_ERROR_CODE,
ErrorLevel.MIDDLE,
singleApi.getFilePath(),
singleApi.getPos(),
ErrorType.ERROR_ERROR_CODE,
LogType.LOG_JSDOC,
toNumber(apiJsdoc.since),
singleApi.getApiName(),
singleApi.getDefinedText(),
errorCodeResult.errorInfo,
compositiveResult,
compositiveLocalResult
);
}
if (!tagInheritCheckResult.state) {
AddErrorLogs.addAPICheckErrorLogs(
ErrorID.WRONG_SCENE_ID,

View File

@ -0,0 +1,32 @@
import {Comment} from "../../../typedef/parser/Comment";
import {ErrorMessage, ErrorTagFormat} from "../../../typedef/checker/result_type";
import {CommonFunctions} from "../../../utils/checkUtils";
export class CheckErrorCode {
static errorCodeList: number[] = [201, 202, 203, 301, 401, 501, 502, 801, 901];
static isArrayNotEmpty(arr: any): boolean {
return Array.isArray(arr) && arr.length > 0;
}
static hasNumberInArray(arr1: number[], arr2: number[]): boolean {
return arr1.every(num => arr2.includes(num));
}
static checkErrorCode(apiJsdoc: Comment.JsDocInfo): ErrorTagFormat {
const checkResult: ErrorTagFormat = {
state: true,
errorInfo: '',
};
const errorCodes = apiJsdoc.errorCodes.filter(number => number > 100 && number < 1000);;
if (this.isArrayNotEmpty(errorCodes)) {
if (!this.hasNumberInArray(errorCodes, this.errorCodeList)) {
checkResult.state = false;
checkResult.errorInfo = ErrorMessage.ERROR_ERROR_CODE;
}
}
return checkResult;
}
}

View File

@ -35,7 +35,8 @@ export enum ErrorType {
API_CHANGE_ERRORS = 'api change errors',
TS_SYNTAX_ERROR = 'TS syntax error',
NO_JSDOC = 'No jsdoc',
JSDOC_HAS_CHINESE = 'JSDOC_HAS_CHINESE'
JSDOC_HAS_CHINESE = 'JSDOC_HAS_CHINESE',
ERROR_ERROR_CODE = 'error_error_code'
}
/**
@ -58,7 +59,8 @@ export enum ErrorID {
API_CHANGE_ERRORS_ID = 12,
TS_SYNTAX_ERROR_ID = 13,
NO_JSDOC_ID = 14,
JSDOC_HAS_CHINESE = 15
JSDOC_HAS_CHINESE = 15,
ERROR_ERROR_CODE
}
/**
@ -150,7 +152,7 @@ export enum ErrorMessage {
ERROR_NO_JSDOC = 'Jsdoc needs to be added to the current API.',
ERROR_NO_JSDOC_TAG = 'add tags to the Jsdoc.',
ERROR_HAS_CHINESE= 'Jsdoc has chinese.',
ERROR_ERROR_CODE = 'The generic error code does not contain the current error code.'
}
export const incompatibleApiDiffTypes: Map<ApiDiffType, ErrorMessage> = new Map([