• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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
16const { getAPINote, ErrorType, ErrorLevel, FileType } = require('./utils');
17const { addAPICheckErrorLogs } = require('./compile_info');
18
19function checkDeprecated(node, sourcefile, fileName) {
20  const apiNote = getAPINote(node);
21  const apiNoteArr = apiNote.split('*');
22  let hasDeprecatedError = false;
23  let errorInfo = '';
24  apiNoteArr.forEach(note => {
25    if (note.match(new RegExp('@deprecated'))) {
26      const deprecatedNote = note.replace('@deprecated', '').trim();
27      const regx = /since [0-9]/;
28      const arr = deprecatedNote.match(regx);
29      if (arr !== null) {
30        const errorNote = deprecatedNote.replace(arr[0], '');
31        if (/[A-z]/.test(errorNote)) {
32          hasDeprecatedError = true;
33          if (errorInfo !== '') {
34            errorInfo += `,${note}`;
35          } else {
36            errorInfo += note;
37          }
38        }
39      } else if (arr === null) {
40        hasDeprecatedError = true;
41        if (errorInfo !== '') {
42          errorInfo += `,${note}`;
43        } else {
44          errorInfo += note;
45        }
46      }
47    }
48  });
49
50  if (hasDeprecatedError) {
51    addAPICheckErrorLogs(node, sourcefile, fileName, ErrorType.UNKNOW_DEPRECATED, errorInfo, FileType.JSDOC,
52      ErrorLevel.MIDDLE);
53  }
54}
55exports.checkDeprecated = checkDeprecated;
56