1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the 'License'); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an 'AS IS' BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import ts from 'typescript'; 17import { ApiDiffType } from '../../typedef/diff/ApiInfoDiff'; 18 19/** 20 * error message type 21 * @enum { string } 22 */ 23export enum ErrorType { 24 UNKNOW_DECORATOR = 'unknow decorator', 25 MISSPELL_WORDS = 'misspell words', 26 NAMING_ERRORS = 'naming errors', 27 UNKNOW_PERMISSION = 'unknow permission', 28 UNKNOW_SYSCAP = 'unknow syscap', 29 UNKNOW_DEPRECATED = 'unknow deprecated', 30 WRONG_ORDER = 'wrong order', 31 WRONG_VALUE = 'wrong value', 32 WRONG_SCENE = 'wrong scene', 33 PARAMETER_ERRORS = 'wrong parameter', 34 API_PAIR_ERRORS = 'limited api pair errors', 35 FORBIDDEN_WORDS = 'forbidden word', 36 API_CHANGE_ERRORS = 'api change errors', 37 TS_SYNTAX_ERROR = 'TS syntax error', 38 NO_JSDOC = 'No jsdoc', 39 JSDOC_HAS_CHINESE = 'JSDOC_HAS_CHINESE', 40 ERROR_ERROR_CODE = 'error_error_code' 41} 42 43/** 44 * error message id 45 * @enum { number } 46 */ 47export enum ErrorID { 48 UNKNOW_DECORATOR_ID = 0, 49 MISSPELL_WORDS_ID = 1, 50 NAMING_ERRORS_ID = 2, 51 UNKNOW_PERMISSION_ID = 3, 52 UNKNOW_SYSCAP_ID = 4, 53 UNKNOW_DEPRECATED_ID = 5, 54 WRONG_ORDER_ID = 6, 55 WRONG_VALUE_ID = 7, 56 WRONG_SCENE_ID = 8, 57 PARAMETER_ERRORS_ID = 9, 58 API_PAIR_ERRORS_ID = 10, 59 FORBIDDEN_WORDS_ID = 11, 60 API_CHANGE_ERRORS_ID = 12, 61 TS_SYNTAX_ERROR_ID = 13, 62 NO_JSDOC_ID = 14, 63 JSDOC_HAS_CHINESE = 15, 64 ERROR_ERROR_CODE = 16 65} 66 67/** 68 * error type 69 * @enum { string } 70 */ 71export enum LogType { 72 LOG_API = 'Api', 73 LOG_JSDOC = 'JsDoc', 74 LOG_FILE = 'File', 75} 76 77/** 78 * error message level 79 * @enum { number } 80 */ 81export enum ErrorLevel { 82 HIGH = 3, 83 MIDDLE = 2, 84 LOW = 1, 85} 86 87export enum ParticularErrorCode { 88 ERROR_CODE_201 = '201', 89 ERROR_CODE_202 = '202', 90 ERROR_CODE_401 = '401', 91 ERROR_PERMISSION = 'permission', 92 ERROR_SYSTEMAPI = 'systemapi' 93} 94 95/** 96 * error message infomation 97 * @enum { string } 98 */ 99export enum ErrorMessage { 100 ERROR_INFO_VALUE_EXTENDS = 'The [extends] tag value is incorrect. Please check if the tag value matches the inherited class name.', 101 ERROR_INFO_VALUE_IMPLEMENTS = 'The [implements] tag value is incorrect. Please check if the tag value matches the inherited class name.', 102 ERROR_INFO_VALUE_ENUM = 'The [enum] tag type is incorrect. Please check if the tag type is { string } or { number }.', 103 ERROR_INFO_VALUE_SINCE = 'The [since] tag value is incorrect. Please check if the tag value is a numerical value.', 104 ERROR_INFO_VALUE_SINCE_NUMBER = 'The [since] value is greater than the latest version number.', 105 ERROR_INFO_VALUE_SINCE_JSDOC = 'The [since] value for different jsdoc should not be the same.', 106 ERROR_INFO_RETURNS = 'The [returns] tag was used incorrectly. The returns tag should not be used when the return type is void.', 107 ERROR_INFO_VALUE_RETURNS = 'The [returns] tag type is incorrect. Please check if the tag type is consistent with the return type.', 108 ERROR_INFO_VALUE_USEINSTEAD = 'The [useinstead] tag value is incorrect. Please check the usage method.', 109 ERROR_INFO_VALUE_TYPE = 'The [type] tag type is incorrect. Please check if the type matches the attribute type.', 110 ERROR_INFO_VALUE_DEFAULT = 'The [default] tag value is incorrect. Please supplement the default value.', 111 ERROR_INFO_VALUE_PERMISSION = 'The [permission] tag value is incorrect. Please check if the permission field has been configured or update the configuration file.', 112 ERROR_INFO_VALUE_DEPRECATED = 'The [deprecated] tag value is incorrect. Please check the usage method.', 113 ERROR_INFO_VALUE_SYSCAP = 'The [syscap] tag value is incorrect. Please check if the syscap field is configured.', 114 ERROR_INFO_VALUE_NAMESPACE = 'The [namespace] tag value is incorrect. Please check if it matches the namespace name.', 115 ERROR_INFO_VALUE_INTERFACE = 'The [interface] label value is incorrect. Please check if it matches the interface name.', 116 ERROR_INFO_VALUE_TYPEDEF = 'The [typedef] tag value is incorrect. Please check if it matches the interface name or type content.', 117 ERROR_INFO_VALUE_STRUCT = 'The [struct] tag value is incorrect. Please check if it matches the struct name.', 118 ERROR_INFO_TYPE_PARAM = 'The type of the [$$] [param] tag is incorrect. Please check if it matches the type of the [$$] parameter.', 119 ERROR_INFO_VALUE_PARAM = 'The value of the [$$] [param] tag is incorrect. Please check if it matches the [$$] parameter name.', 120 ERROR_INFO_VALUE1_THROWS = 'The type of the [$$] [throws] tag is incorrect. Please fill in [BusinessError].', 121 ERROR_INFO_VALUE2_THROWS = 'The type of the [$$] [throws] tag is incorrect. Please check if the tag value is a numerical value.', 122 ERROR_INFO_VALUE3_THROWS = 'The description of the [401 throws] is incorrect. please fix it according to the specification.', 123 ERROR_INFO_INHERIT = 'It was detected that there is an inheritable label [$$] in the current file, but there are child nodes without this label.', 124 ERROR_INFO_FOLLOW = 'It was detected that there is a following label [$$] in the current file, but the parent nodes without this label.', 125 ERROR_ORDER = 'JSDoc label order error, please adjust the order of [$$] labels.', 126 ERROR_LABELNAME = 'The [$$] tag does not exist. Please use a valid JSDoc tag.', 127 ERROR_LOST_LABEL = 'JSDoc tag validity verification failed. Please confirm if the [$$] tag is missing.', 128 ERROR_USE = 'JSDoc label validity verification failed. The [$$] label is not allowed. Please check the label usage method.', 129 ERROR_MORELABEL = 'JSDoc tag validity verification failed.There are [$$] redundant [$$]. Please check if the tag should be deleted.', 130 ERROR_REPEATLABEL = 'The validity verification of the JSDoc tag failed. The [$$] tag is not allowed to be reused, please delete the extra tags.', 131 ERROR_USE_INTERFACE = 'The validity verification of the JSDoc tag failed. The [interface] tag and [typedef] tag are not allowed to be used simultaneously. Please confirm the interface class.', 132 ERROR_EVENT_NAME_STRING = 'The event name should be string.', 133 ERROR_EVENT_NAME_NULL = 'The event name cannot be Null value.', 134 ERROR_EVENT_NAME_SMALL_HUMP = 'The event name should be named by small hump. (Received ["$$"]).', 135 ERROR_EVENT_CALLBACK_OPTIONAL = 'The callback parameter of off function should be optional.', 136 ERROR_EVENT_CALLBACK_MISSING = 'The off functions of one single event should have at least one callback parameter, and the callback parameter should be the last parameter.', 137 ERROR_EVENT_ON_AND_OFF_PAIR = 'The on and off event subscription methods do not appear in pair.', 138 ERROR_EVENT_WITHOUT_PARAMETER = 'The event subscription methods should has at least one parameter.', 139 ILLEGAL_USE_ANY = 'Illegal [$$] keyword used in the API.', 140 ERROR_CHANGES_VERSION = 'Please check if the changed API version number is 10.', 141 ERROR_WORD = 'Error words in [$$]: {$$}. please confirm whether it needs to be corrected to a common word.', 142 ERROR_NAMING = 'Prohibited word in [$$]:{$$}.The word allowed is [$$].', 143 ERROR_SCENARIO = 'Prohibited word in [$$]:{$$} in the [$$] file.', 144 ERROR_UPPERCASE_NAME = 'This name [$$] should be named by all uppercase.', 145 ERROR_LARGE_HUMP_NAME = 'This name [$$] should be named by large hump.', 146 ERROR_SMALL_HUMP_NAME = 'This name [$$] should be named by small hump.', 147 ERROR_SMALL_HUMP_NAME_FILE = 'This API file should be named by small hump.', 148 ERROR_LARGE_HUMP_NAME_FILE = 'This API file should be named by large hump.', 149 ERROR_ANONYMOUS_FUNCTION = 'Anonymous functions or anonymous object that are not allowed are used in this api.', 150 ERROR_NO_JSDOC = 'Jsdoc needs to be added to the current API.', 151 ERROR_NO_JSDOC_TAG = 'add tags to the Jsdoc.', 152 ERROR_HAS_CHINESE = 'Jsdoc has chinese.', 153 ERROR_ERROR_CODE = 'The generic error code does not contain the current error code.', 154 ERROR_ERROR_SYSTEMAPI_ATOMICSERVICE = 'The [systemapi] and [atomicservice] cannot exist in the same doc.', 155 ERROR_CHANGES_JSDOC_LEVEL = 'Forbid changes: Cannot change from public API to system API.', 156 ERROR_CHANGES_JSDOC_PERMISSION_RANGE = 'Forbid changes: Cannot reduce or permission or increase and permission.', 157 ERROR_CHANGES_JSDOC_PERMISSION_VALUE = 'Forbid changes: Cannot change permission value,cannot judge the range change.', 158 ERROR_CHANGES_JSDOC_ERROR_CODE_ADD = 'Forbid changes: The number of error codes cannot be increased from 0 to multiple error codes.', 159 ERROR_CHANGES_JSDOC_ERROR_CODE_VALUE = 'Forbid changes: Cannot change the error code value.', 160 ERROR_CHANGES_JSDOC_CARD = 'Forbid changes: The card application cannot be changed from supported to not supported.', 161 ERROR_CHANGES_JSDOC_CROSS_PLATFORM = 'Forbid changes: Crossplatform cannot be changed from supported to not supported.', 162 ERROR_CHANGES_JSDOC_API_DELETE = 'Forbid changes: API cannot be deleted.', 163 ERROR_CHANGES_JSDOC_FA_TO_STAGE = 'Forbid changes: Cannot change from FAModelOnly to StageModelOnly.', 164 ERROR_CHANGES_JSDOC_STAGE_TO_FA = 'Forbid changes: Cannot change from StageModelOnly to FAModelOnly.', 165 ERROR_CHANGES_JSDOC_NA_TO_STAGE = 'Forbid changes: Cannot change from nothing to StageModelOnly.', 166 ERROR_CHANGES_JSDOC_NA_TO_FA = 'Forbid changes: Cannot change from nothing to FAModelOnly.', 167 ERROR_CHANGES_JSDOC_ATOMICSERVICE_TO_NA = 'Forbid changes: Cannot change from atomicservice to NA.', 168 ERROR_CHANGES_FUNCTION_RETURN_TYPE_ADD = 'Forbid changes: The function return value type cannot be extended.', 169 ERROR_CHANGES_FUNCTION_RETURN_TYPE_REDUCE = 'Forbid changes: The function return value type cannot be reduced.', 170 ERROR_CHANGES_FUNCTION_RETURN_TYPE_CHANGE = 'Forbid changes: Cannot change function return value type.', 171 ERROR_CHANGES_FUNCTION_PARAM_POS_CHANGE = 'Forbid changes: Cannot change function param position.', 172 ERROR_CHANGES_FUNCTION_PARAM_REQUIRED_ADD = 'Forbid changes: Cannot add function required param.', 173 ERROR_CHANGES_FUNCTION_PARAM_REDUCE = 'Forbid changes: Cannot delete function param.', 174 ERROR_CHANGES_FUNCTION_PARAM_TO_REQUIRED = 'Forbid changes: Cannot change form unrequired param to required param.', 175 ERROR_CHANGES_FUNCTION_PARAM_TYPE = 'Forbid changes: Cannot change function param type.', 176 ERROR_CHANGES_FUNCTION_PARAM_TYPE_REDUCE = 'Forbid changes: The function param type range is cannot be reduced.', 177 ERROR_CHANGES_PROPERTY_READONLY_TO_REQUIRED = 'Forbid changes: Read-only properties cannot be changed from optional to required.', 178 ERROR_CHANGES_PROPERTY_WRITABLE_TO_UNREQUIRED = 'Forbid changes: Writable properties cannot be changed from required to optional.', 179 ERROR_CHANGES_PROPERTY_WRITABLE_TO_REQUIRED = 'Forbid changes: Writable properties cannot be changed from optional to required.', 180 ERROR_CHANGES_PROPERTY_TYPE_CHANGE = 'Forbid changes: Cannot change property type.', 181 ERROR_CHANGES_PROPERTY_READONLY_ADD = 'Forbid changes: Cannot Expand the range of readonly property types.', 182 ERROR_CHANGES_PROPERTY_WRITABLE_ADD = 'Forbid changes: Cannot Expand the range of writable property types.', 183 ERROR_CHANGES_PROPERTY_WRITABLE_REDUCE = 'Forbid changes: Cannot reduce the range of writable property types.', 184 ERROR_CHANGES_DELETE_DECORATOR = 'Forbid changes: Decorator cannot be deleted.', 185 ERROR_CHANGES_CONSTANT_VALUE = 'Forbid changes: Cannot change constant value.', 186 ERROR_CHANGES_TYPE_ALIAS_VALUE = 'Forbid changes: Cannot change custom type value.', 187 ERROR_CHANGES_TYPE_ALIAS_ADD = 'Forbid changes: Cannot expand the range of custom type.', 188 ERROR_CHANGES_TYPE_ALIAS_REDUCE = 'Forbid changes: Cannot reduce the range of custom type.', 189 ERROR_CHANGES_ENUM_MEMBER_VALUE = 'Forbid changes: Cannot change Enumeration assignment.', 190 ERROR_CHANGES_JSDOC_CHANGE = 'Forbid changes: Historical JSDoc cannot be changed.', 191 ERROR_CHANGES_JSDOC_NUMBER = 'Forbid changes: API changes must add a new section of JSDoc.', 192 ERROR_CHANGES_SYSCAP_NA_TO_HAVE = 'Forbid changes: Cannot change from NA to syscap.', 193 ERROR_CHANGES_SYSCAP_HAVE_TO_NA = 'Forbid changes: Cannot change from syscap to NA.', 194 ERROR_CHANGES_SYSCAP_A_TO_B = 'Forbid changes: Cannot change syscap value.', 195 ERROR_CHANGES_ADD_PROPERTY = 'Forbid changes: Cannot add new property to interface API.', 196} 197 198export const incompatibleApiDiffTypes: Map<ApiDiffType, ErrorMessage> = new Map( 199 [ 200 [ApiDiffType.HISTORICAL_JSDOC_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_CHANGE], 201 [ApiDiffType.HISTORICAL_API_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_NUMBER], 202 // 1.访问级别变更 203 [ApiDiffType.PUBLIC_TO_SYSTEM, ErrorMessage.ERROR_CHANGES_JSDOC_LEVEL], 204 // 2.权限变更 205 [ApiDiffType.PERMISSION_NA_TO_HAVE, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION_VALUE], 206 [ApiDiffType.PERMISSION_RANGE_SMALLER, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION_RANGE], 207 [ApiDiffType.PERMISSION_RANGE_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION_VALUE], 208 // 3.错误码变更 209 [ApiDiffType.ERROR_CODE_NA_TO_HAVE, ErrorMessage.ERROR_CHANGES_JSDOC_ERROR_CODE_ADD], 210 [ApiDiffType.ERROR_CODE_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_ERROR_CODE_VALUE], 211 // 4.是否支持卡片应用 212 [ApiDiffType.CARD_TO_NA, ErrorMessage.ERROR_CHANGES_JSDOC_CARD], 213 // 5.是否支持跨平台 214 [ApiDiffType.CROSS_PLATFORM_TO_NA, ErrorMessage.ERROR_CHANGES_JSDOC_CROSS_PLATFORM], 215 // 7.api删除 216 [ApiDiffType.REDUCE, ErrorMessage.ERROR_CHANGES_JSDOC_API_DELETE], 217 // 8.模型使用限制变更 218 [ApiDiffType.FA_TO_STAGE, ErrorMessage.ERROR_CHANGES_JSDOC_FA_TO_STAGE], 219 [ApiDiffType.STAGE_TO_FA, ErrorMessage.ERROR_CHANGES_JSDOC_STAGE_TO_FA], 220 [ApiDiffType.NA_TO_STAGE, ErrorMessage.ERROR_CHANGES_JSDOC_NA_TO_STAGE], 221 [ApiDiffType.NA_TO_FA, ErrorMessage.ERROR_CHANGES_JSDOC_NA_TO_FA], 222 // 10.函数变更 223 [ApiDiffType.FUNCTION_RETURN_TYPE_ADD, ErrorMessage.ERROR_CHANGES_FUNCTION_RETURN_TYPE_ADD], 224 [ApiDiffType.FUNCTION_RETURN_TYPE_REDUCE, ErrorMessage.ERROR_CHANGES_FUNCTION_RETURN_TYPE_REDUCE], 225 [ApiDiffType.FUNCTION_RETURN_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_FUNCTION_RETURN_TYPE_CHANGE], 226 [ApiDiffType.FUNCTION_PARAM_POS_CHANGE, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_POS_CHANGE], 227 [ApiDiffType.FUNCTION_PARAM_REQUIRED_ADD, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_REQUIRED_ADD], 228 [ApiDiffType.FUNCTION_PARAM_REDUCE, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_REDUCE], 229 [ApiDiffType.FUNCTION_PARAM_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_TO_REQUIRED], 230 [ApiDiffType.FUNCTION_PARAM_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_TYPE], 231 [ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE, ErrorMessage.ERROR_CHANGES_FUNCTION_PARAM_TYPE_REDUCE], 232 // 12.属性变更 233 [ApiDiffType.PROPERTY_READONLY_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY_READONLY_TO_REQUIRED], 234 [ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY_WRITABLE_TO_UNREQUIRED], 235 [ApiDiffType.PROPERTY_WRITABLE_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY_WRITABLE_TO_REQUIRED], 236 [ApiDiffType.PROPERTY_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_PROPERTY_TYPE_CHANGE], 237 [ApiDiffType.PROPERTY_READONLY_ADD, ErrorMessage.ERROR_CHANGES_PROPERTY_READONLY_ADD], 238 [ApiDiffType.PROPERTY_WRITABLE_ADD, ErrorMessage.ERROR_CHANGES_PROPERTY_WRITABLE_ADD], 239 [ApiDiffType.PROPERTY_WRITABLE_REDUCE, ErrorMessage.ERROR_CHANGES_PROPERTY_WRITABLE_REDUCE], 240 [ApiDiffType.DELETE_DECORATOR, ErrorMessage.ERROR_CHANGES_DELETE_DECORATOR], 241 // 13.常量变更 242 [ApiDiffType.CONSTANT_VALUE_CHANGE, ErrorMessage.ERROR_CHANGES_CONSTANT_VALUE], 243 // 14.自定义类型变更 244 [ApiDiffType.TYPE_ALIAS_CHANGE, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS_VALUE], 245 [ApiDiffType.TYPE_ALIAS_ADD, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS_ADD], 246 [ApiDiffType.TYPE_ALIAS_REDUCE, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS_REDUCE], 247 // 15.枚举类型变更 248 [ApiDiffType.ENUM_MEMBER_VALUE_CHANGE, ErrorMessage.ERROR_CHANGES_ENUM_MEMBER_VALUE], 249 // 16.是否拥有元服务能力 250 [ApiDiffType.ATOMIC_SERVICE_HAVE_TO_NA, ErrorMessage.ERROR_CHANGES_JSDOC_ATOMICSERVICE_TO_NA], 251 // 17.syscap变更 252 [ApiDiffType.SYSCAP_NA_TO_HAVE, ErrorMessage.ERROR_CHANGES_SYSCAP_NA_TO_HAVE], 253 [ApiDiffType.SYSCAP_HAVE_TO_NA, ErrorMessage.ERROR_CHANGES_SYSCAP_HAVE_TO_NA], 254 [ApiDiffType.SYSCAP_A_TO_B, ErrorMessage.ERROR_CHANGES_SYSCAP_A_TO_B], 255 // 18.interface不允许新增属性 256 [ApiDiffType.ADD, ErrorMessage.ERROR_CHANGES_ADD_PROPERTY] 257 ] 258); 259 260/** 261 * online error message format 262 */ 263export class ApiResultSimpleInfo { 264 id: number = -1; 265 level: number = -1; 266 filePath: string = ''; 267 location: string = ''; 268 message: string = ''; 269 type: string = ''; 270 apiText: string = ''; 271 apiName: string = ''; 272 apiType: string = ''; 273 hierarchicalRelations: string = ''; 274 parentModuleName: string | undefined = ''; 275 276 setID(id: number): ApiResultSimpleInfo { 277 this.id = id; 278 return this; 279 } 280 281 getID(): number { 282 return this.id; 283 } 284 285 setLevel(level: number): ApiResultSimpleInfo { 286 this.level = level; 287 return this; 288 } 289 290 getLevel(): number { 291 return this.level; 292 } 293 294 setLocation(location: string): ApiResultSimpleInfo { 295 this.location = location; 296 return this; 297 } 298 299 getLocation(): string { 300 return this.location; 301 } 302 303 setFilePath(fileFilePath: string): ApiResultSimpleInfo { 304 this.filePath = fileFilePath; 305 return this; 306 } 307 308 getFilePath(): string { 309 return this.filePath; 310 } 311 312 setMessage(message: string): ApiResultSimpleInfo { 313 this.message = message; 314 return this; 315 } 316 317 getMessage(): string { 318 return this.message; 319 } 320 321 setType(type: string): ApiResultSimpleInfo { 322 this.type = type; 323 return this; 324 } 325 326 getType(): string { 327 return this.type; 328 } 329 330 setApiText(apiText: string): ApiResultSimpleInfo { 331 this.apiText = apiText; 332 return this; 333 } 334 335 getApiText(): string { 336 return this.apiText; 337 } 338 339 340 setApiName(apiName: string): ApiResultSimpleInfo { 341 this.apiName = apiName; 342 return this; 343 } 344 345 getApiName(): string { 346 return this.apiName; 347 } 348 349 setApiType(apiType: string): ApiResultSimpleInfo { 350 this.apiType = apiType; 351 return this; 352 } 353 354 getApiType(): string { 355 return this.apiType; 356 } 357 358 setHierarchicalRelations(hierarchicalRelations: string): ApiResultSimpleInfo { 359 this.hierarchicalRelations = hierarchicalRelations; 360 return this; 361 } 362 363 getHierarchicalRelations(): string { 364 return this.hierarchicalRelations; 365 } 366 367 setParentModuleName(parentModuleName: string | undefined): ApiResultSimpleInfo { 368 this.parentModuleName = parentModuleName; 369 return this; 370 } 371 372 getParentModuleName(): string | undefined { 373 return this.parentModuleName; 374 } 375} 376 377/** 378 * local excel table error message format 379 */ 380export class ApiResultInfo { 381 errorType: string = ''; 382 location: string = ''; 383 apiType: string = ''; 384 message: string = ''; 385 version: number = -1; 386 level: number = -1; 387 apiName: string = ''; 388 apiFullText: string = ''; 389 baseName: string = ''; 390 hierarchicalRelations: string = ''; 391 parentModuleName: string | undefined = ''; 392 defectType: string = ''; 393 394 setErrorType(errorType: string): ApiResultInfo { 395 this.errorType = errorType; 396 return this; 397 } 398 399 getErrorType(): string { 400 return this.errorType; 401 } 402 403 setLocation(location: string): ApiResultInfo { 404 this.location = location; 405 return this; 406 } 407 408 getLocation(): string { 409 return this.location; 410 } 411 setApiType(apiType: string): ApiResultInfo { 412 this.apiType = apiType; 413 return this; 414 } 415 416 getApiType(): string { 417 return this.apiType; 418 } 419 420 setMessage(message: string): ApiResultInfo { 421 this.message = message; 422 return this; 423 } 424 425 getMessage(): string { 426 return this.message; 427 } 428 429 setVersion(version: number): ApiResultInfo { 430 this.version = version; 431 return this; 432 } 433 434 getVersion(): number { 435 return this.version; 436 } 437 438 setLevel(level: number): ApiResultInfo { 439 this.level = level; 440 return this; 441 } 442 443 getLevel(): number { 444 return this.level; 445 } 446 447 setApiName(apiName: string): ApiResultInfo { 448 this.apiName = apiName; 449 return this; 450 } 451 452 getApiName(): string { 453 return this.apiName; 454 } 455 456 setApiFullText(apiFullText: string): ApiResultInfo { 457 this.apiFullText = apiFullText; 458 return this; 459 } 460 461 getApiFullText(): string { 462 return this.apiFullText; 463 } 464 setBaseName(baseName: string): ApiResultInfo { 465 this.baseName = baseName; 466 return this; 467 } 468 469 getBaseName(): string { 470 return this.baseName; 471 } 472 473 setHierarchicalRelations(hierarchicalRelations: string): ApiResultInfo { 474 this.hierarchicalRelations = hierarchicalRelations; 475 return this; 476 } 477 478 getHierarchicalRelations(): string { 479 return this.hierarchicalRelations; 480 } 481 482 setParentModuleName(parentModuleName: string | undefined): ApiResultInfo { 483 this.parentModuleName = parentModuleName; 484 return this; 485 } 486 487 getParentModuleName(): string | undefined { 488 return this.parentModuleName; 489 } 490 491 setDefectType(defectType: string): ApiResultInfo { 492 this.defectType = defectType; 493 return this; 494 } 495 496 getDefectType(): string { 497 return this.defectType; 498 } 499} 500 501/** 502 * error message format 503 */ 504export interface ErrorTagFormat { 505 state: boolean; 506 errorInfo: string; 507} 508 509/** 510 * permission message format 511 */ 512export interface PermissionData { 513 name: string; 514 grantMode: string; 515 since: number; 516 deprecated: string; 517 availableLevel: string; 518 provisionEnable: boolean; 519 distributedSceneEnable: boolean; 520 label: string; 521 description: string; 522} 523 524/** 525 * naming dictionary format 526 */ 527export interface NameDictionaryType { 528 badWord: string; 529 suggestion: string; 530 ignore: string[]; 531} 532 533/** 534 * naming dictionary format for file 535 */ 536export interface NameScenarioType { 537 word: string; 538 files: string[]; 539} 540 541/** 542 * error message format 543 */ 544export class ApiResultMessage { 545 analyzerName: string = 'apiengine'; 546 buggyFilePath: string = ''; 547 codeContextStaerLine: string = ''; 548 defectLevel: number = -1; 549 defectType: string = ''; 550 description: string = ''; 551 language: string = 'typescript'; 552 mainBuggyCode: string = ''; 553 mainBuggyLine: string = ''; 554 extendInfo: ApiBaseInfo = new ApiBaseInfo(); 555 556 setLocation(codeContextStaerLine: string): ApiResultMessage { 557 this.codeContextStaerLine = codeContextStaerLine; 558 return this; 559 } 560 561 getLocation(): string { 562 return this.codeContextStaerLine; 563 } 564 565 setLevel(defectLevel: number): ApiResultMessage { 566 this.defectLevel = defectLevel; 567 return this; 568 } 569 570 getLevel(): number { 571 return this.defectLevel; 572 } 573 574 setType(defectType: string): ApiResultMessage { 575 this.defectType = defectType; 576 return this; 577 } 578 579 getType(): string { 580 return this.defectType; 581 } 582 583 setFilePath(fileFilePath: string): ApiResultMessage { 584 this.buggyFilePath = fileFilePath; 585 return this; 586 } 587 588 getFilePath(): string { 589 return this.buggyFilePath; 590 } 591 592 setMessage(description: string): ApiResultMessage { 593 this.description = description; 594 return this; 595 } 596 597 getMessage(): string { 598 return this.description; 599 } 600 setMainBuggyCode(mainBuggyCode: string): ApiResultMessage { 601 this.mainBuggyCode = mainBuggyCode; 602 return this; 603 } 604 605 getMainBuggyCode(): string { 606 return this.mainBuggyCode; 607 } 608 609 setMainBuggyLine(mainBuggyLine: string): ApiResultMessage { 610 this.mainBuggyLine = mainBuggyLine; 611 return this; 612 } 613 614 getMainBuggyLine(): string { 615 return this.mainBuggyLine; 616 } 617 618 setExtendInfo(extendInfo: ApiBaseInfo): ApiResultMessage { 619 this.extendInfo = extendInfo; 620 return this; 621 } 622 623 getExtendInfo(): ApiBaseInfo { 624 return this.extendInfo; 625 } 626} 627 628/** 629 * error message format 630 */ 631export class ApiCheckInfo { 632 errorID: number = -1; 633 errorLevel: number = -1; 634 filePath: string = ''; 635 apiPostion: ts.LineAndCharacter = { line: -1, character: -1 }; 636 errorType: string = ''; 637 logType: string = ''; 638 sinceNumber: number = -1; 639 apiName: string = ''; 640 apiType: string = ''; 641 apiText: string = ''; 642 errorInfo: string = ''; 643 hierarchicalRelations: string = ''; 644 parentModuleName: string | undefined = ''; 645 646 setErrorID(errorID: number): ApiCheckInfo { 647 this.errorID = errorID; 648 return this; 649 } 650 651 getErrorID(): number { 652 return this.errorID; 653 } 654 655 setErrorLevel(errorLevel: number): ApiCheckInfo { 656 this.errorLevel = errorLevel; 657 return this; 658 } 659 660 getErrorLevel(): number { 661 return this.errorLevel; 662 } 663 664 setFilePath(filePath: string): ApiCheckInfo { 665 this.filePath = filePath; 666 return this; 667 } 668 669 getFilePath(): string { 670 return this.filePath; 671 } 672 673 setApiPostion(apiPostion: ts.LineAndCharacter): ApiCheckInfo { 674 this.apiPostion = apiPostion; 675 return this; 676 } 677 678 getApiPostion(): ts.LineAndCharacter { 679 return this.apiPostion; 680 } 681 682 setErrorType(errorType: string): ApiCheckInfo { 683 this.errorType = errorType; 684 return this; 685 } 686 687 getErrorType(): string { 688 return this.errorType; 689 } 690 691 setLogType(logType: string): ApiCheckInfo { 692 this.logType = logType; 693 return this; 694 } 695 696 getLogType(): string { 697 return this.logType; 698 } 699 700 setSinceNumber(sinceNumber: number): ApiCheckInfo { 701 this.sinceNumber = sinceNumber; 702 return this; 703 } 704 705 getSinceNumber(): number { 706 return this.sinceNumber; 707 } 708 709 setApiName(apiName: string): ApiCheckInfo { 710 this.apiName = apiName; 711 return this; 712 } 713 714 getApiName(): string { 715 return this.apiName; 716 } 717 718 setApiType(apiType: string): ApiCheckInfo { 719 this.apiType = apiType; 720 return this; 721 } 722 723 getApiType(): string { 724 return this.apiType; 725 } 726 727 setApiText(apiText: string): ApiCheckInfo { 728 this.apiText = apiText; 729 return this; 730 } 731 732 getApiText(): string { 733 return this.apiText; 734 } 735 736 setErrorInfo(errorInfo: string): ApiCheckInfo { 737 this.errorInfo = errorInfo; 738 return this; 739 } 740 741 getErrorInfo(): string { 742 return this.errorInfo; 743 } 744 745 setHierarchicalRelations(hierarchicalRelations: string): ApiCheckInfo { 746 this.hierarchicalRelations = hierarchicalRelations; 747 return this; 748 } 749 750 getHierarchicalRelations(): string { 751 return this.hierarchicalRelations; 752 } 753 754 setParentModuleName(parentModuleName: string | undefined): ApiCheckInfo { 755 this.parentModuleName = parentModuleName; 756 return this; 757 } 758 759 getParentModuleName(): string | undefined { 760 return this.parentModuleName; 761 } 762} 763 764export class ApiBaseInfo { 765 apiName: string = ''; 766 apiType: string = ''; 767 hierarchicalRelations: string = ''; 768 parentModuleName: string | undefined = ''; 769 770 setApiName(apiName: string): ApiBaseInfo { 771 this.apiName = apiName; 772 return this; 773 } 774 775 getApiName(): string { 776 return this.apiName; 777 } 778 setApiType(apiType: string): ApiBaseInfo { 779 this.apiType = apiType; 780 return this; 781 } 782 783 getApiType(): string { 784 return this.apiType; 785 } 786 setHierarchicalRelations(hierarchicalRelations: string): ApiBaseInfo { 787 this.hierarchicalRelations = hierarchicalRelations; 788 return this; 789 } 790 791 getHierarchicalRelations(): string { 792 return this.hierarchicalRelations; 793 } 794 setParentModuleName(parentModuleName: string | undefined): ApiBaseInfo { 795 this.parentModuleName = parentModuleName; 796 return this; 797 } 798 799 getParentModuleName(): string | undefined { 800 return this.parentModuleName; 801 } 802 803} 804 805export class ErrorBaseInfo { 806 errorID: number = -1; 807 errorLevel: number = -1; 808 errorType: string = ''; 809 logType: string = ''; 810 errorInfo: string = ''; 811 812 setErrorID(errorID: number): ErrorBaseInfo { 813 this.errorID = errorID; 814 return this; 815 } 816 817 getErrorID(): number { 818 return this.errorID; 819 } 820 821 setErrorLevel(errorLevel: number): ErrorBaseInfo { 822 this.errorLevel = errorLevel; 823 return this; 824 } 825 826 getErrorLevel(): number { 827 return this.errorLevel; 828 } 829 830 831 setErrorType(errorType: string): ErrorBaseInfo { 832 this.errorType = errorType; 833 return this; 834 } 835 836 getErrorType(): string { 837 return this.errorType; 838 } 839 840 setLogType(logType: string): ErrorBaseInfo { 841 this.logType = logType; 842 return this; 843 } 844 845 getLogType(): string { 846 return this.logType; 847 } 848 849 setErrorInfo(errorInfo: string): ErrorBaseInfo { 850 this.errorInfo = errorInfo; 851 return this; 852 } 853 854 getErrorInfo(): string { 855 return this.errorInfo; 856 } 857} 858 859/** 860 * check工具入口传参 861 * 862 * @interface checkEntryType 863 */ 864export interface checkEntryType { 865 /** 866 * 文件路径集合 867 * 868 * @type {string[]} 869 */ 870 filePathArr: string[]; 871 872 /** 873 * 规则集合,全部规则为第一个字符串为all 874 * 875 * @type {string[]} 876 */ 877 fileRuleArr: string[]; 878 879 /** 880 * 输出路径 881 * 882 * @type {string} 883 */ 884 output: string; 885 886 /** 887 * check中判断diff数据时的路径 888 * 线上为prid,通过服务器获取差异文件 889 * 本地为diff文件,需要包含old和new两个文件 890 * 891 * @type {string} 892 */ 893 prId: string; 894 895 /** 896 * 是否输出excel 897 * 898 * @type {string} 899 * @memberof checkEntry 900 */ 901 isOutExcel: string; 902 903 /** 904 * 是否为增量检查 905 * 906 * @default true 907 * @type {boolean} 908 * @memberof checkEntryType 909 */ 910 isIncrement: boolean; 911}