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 { Comment } from '../../../typedef/parser/Comment'; 17import { ErrorTagFormat, ErrorMessage } from '../../../typedef/checker/result_type'; 18import { CommonFunctions } from '../../../utils/checkUtils'; 19 20export class TagRepeatCheck { 21 /** 22 * jsdoc tag repeat check 23 * @param { Comment.JsDocInfo } apiJsdoc 24 * @returns { ErrorTagFormat[] } 25 */ 26 static tagRepeatCheck(apiJsdoc: Comment.JsDocInfo): ErrorTagFormat[] { 27 const tagRepeatCheckResult: ErrorTagFormat[] = []; 28 const multipleTags: string[] = ['throws', 'param']; 29 const tagNameArr: string[] = []; 30 apiJsdoc.tags?.forEach((tag) => { 31 tagNameArr.push(tag.tag); 32 }); 33 const duplicateArr: string[] = tagNameArr.filter((item) => { 34 return tagNameArr.indexOf(item) !== tagNameArr.lastIndexOf(item); 35 }); 36 const duplicateSet: Set<string> = new Set(duplicateArr); 37 duplicateSet.forEach((duplicateTag) => { 38 if (!multipleTags.includes(duplicateTag)) { 39 const tagRepeatCheckFormat: ErrorTagFormat = { 40 state: false, 41 errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_REPEATLABEL, [duplicateTag]), 42 }; 43 tagRepeatCheckResult.push(tagRepeatCheckFormat); 44 } 45 }); 46 return tagRepeatCheckResult; 47 } 48} 49