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 */ 15const path = require('path'); 16const result = require('../check_result.json'); 17const { apiCheckArr, getApiInfo, ErrorLevel, ApiCheckResult, apiCheckInfoArr } = require('../src/utils'); 18 19/** 20 * 21 * @param {ts.Node} node current node 22 * @param {ts.Sourcefile} sourcefile root node 23 * @param {String} fileName full file name 24 * @param {String} errorType enum object:ErrorType 25 * @param {String} errorInfo error infomation 26 * @param {String} type jsdoc | api 27 * @param {Enum} level enum object:ErrorLevel 28 */ 29function addAPICheckErrorLogs(node, sourcefile, fileName, errorType, errorInfo, type, level) { 30 if (level === ErrorLevel.HIGH || level === ErrorLevel.MIDDLE) { 31 ApiCheckResult.formatCheckResult = false; 32 } 33 const checkFailFileNameSet = new Set(result.apiFiles); 34 if (!checkFailFileNameSet.has(fileName)) { 35 result.apiFiles.push(fileName); 36 } 37 const posOfNode = sourcefile.getLineAndCharacterOfPosition(node.getStart()); 38 const baseFileName = fileName.substring(fileName.indexOf('api'), fileName.length); 39 const errorMessage = `API check error of [${errorType.description}]: ${errorInfo}`; 40 41 apiCheckArr.push({ 42 errorType: errorType.description, 43 fileName: `${baseFileName}(line: ${posOfNode.line + 1}, col: ${posOfNode.character + 1})`, 44 type, 45 errorInfo, 46 version: getApiInfo(node).version, 47 basename: path.basename(fileName).replace(/\.d\.ts/g, ''), 48 level, 49 apiName: node.symbol ? node.symbol.escapedName : '', 50 apiFullText: node.getFullText(), 51 }); 52 53 apiCheckInfoArr.push({ 54 id: errorType.id, 55 level, 56 location: `${baseFileName}(line: ${posOfNode.line + 1}, col: ${posOfNode.character + 1})`, 57 filePath: baseFileName, 58 message: errorMessage, 59 }); 60} 61exports.addAPICheckErrorLogs = addAPICheckErrorLogs; 62