• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { ErrorTagFormat, ErrorMessage } from '../../../typedef/checker/result_type';
17import { ClassInfo } from '../../../typedef/parser/ApiInfoDefination';
18import { CommonFunctions } from '../../../utils/checkUtils';
19
20export class ForbiddenWordsCheck {
21  /**
22   * forbidden words check-'any','this','unknow'
23   * @param { ClassInfo } singleApi -single api info
24   * @returns { ErrorTagFormat }
25   */
26  static forbiddenWordsCheck(singleApi: ClassInfo): ErrorTagFormat {
27    const forbiddenWordsArr: string[] = ['any', 'this', 'unknown'];
28    const forbiddenWordsResult: ErrorTagFormat = {
29      state: true,
30      errorInfo: '',
31    };
32    const apiFullText: string = singleApi.getDefinedText();
33    const reg = /\s{2,}/g;
34    const regx = /(\/\*|\*\/|\*)|\{|\}|\\n|\@|\.|\:|\,|\;|\(|\)|\"|\[|\]/g;
35    const fullText = apiFullText.replace(regx, ' ').replace(reg, ' ');
36    let apiTextWordsArr = fullText.split(/\s/g);
37    apiTextWordsArr.forEach((apiTextWord) => {
38      if (forbiddenWordsArr.includes(apiTextWord)) {
39        forbiddenWordsResult.state = false;
40        forbiddenWordsResult.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ILLEGAL_USE_ANY, [apiTextWord]);
41      }
42    });
43    return forbiddenWordsResult;
44  }
45}
46