fix:api_check门禁报错修复

Signed-off-by: fanjiaojiao <fanjiaojiao@huawei.com>
This commit is contained in:
fanjiaojiao 2023-05-15 15:24:26 +08:00
parent ea097eae85
commit 22fc0b2eb8
5 changed files with 23 additions and 23 deletions

View File

@ -17,7 +17,7 @@
### permission文件配置 ### permission文件配置
在api_check_plugin/config文件夹下创建名为“config.json”的文件用于存放permission配置文件。打开链接中的仓库打开systemres/main/config.json文件将文件内容复制到刚创建的api_check_plugin/config/config.json中 在api_check_plugin/config文件夹下存在名为“config.json”的文件用于存放permission配置文件。打开链接中的仓库打开systemres/main/config.json文件将文件内容复制到api_check_plugin/config/config.json中(覆盖原内容)
[utils_system_resources: Providing system resources such as fonts | 字体等系统资源 (gitee.com)](https://gitee.com/openharmony/utils_system_resources) [utils_system_resources: Providing system resources such as fonts | 字体等系统资源 (gitee.com)](https://gitee.com/openharmony/utils_system_resources)

View File

@ -0,0 +1,5 @@
{
"module": {
"definePermissions": []
}
}

View File

@ -20,7 +20,7 @@ const urlSuffix = '/systemres/main/config.json';
exports.checkJSDoc = function (node, sourceFile, fileName) { exports.checkJSDoc = function (node, sourceFile, fileName) {
const checkLegality = require('./src/check_legality'); const checkLegality = require('./src/check_legality');
return checkLegality.checkJsDocOfCurrentNode(node, sourceFile, undefined, fileName); return checkLegality.checkJsDocOfCurrentNode(node, sourceFile, fileName);
}; };
exports.initEnv = function (version) { exports.initEnv = function (version) {

View File

@ -84,8 +84,7 @@ function checkAllNode(node, sourcefile, fileName) {
checkPermission(node, sourcefile, fileName); checkPermission(node, sourcefile, fileName);
if (commentNodeWhiteList.includes(node.kind)) { if (commentNodeWhiteList.includes(node.kind)) {
const permissionConfigPath = require('../config/config.json'); checkJSDoc(node, sourcefile, fileName);
checkJSDoc(node, sourcefile, permissionConfigPath, fileName);
} }
} }

View File

@ -54,26 +54,26 @@ function checkJsDocLegality(node, comments, checkInfoMap) {
// 'param' // 'param'
legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor], ['param'], true, checkInfoMap, ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature, ts.SyntaxKind.Constructor], ['param'], true, checkInfoMap,
(currentNode, checkResult) => { (currentNode, checkResult) => {
if (!new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, if (!new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.Constructor]).has(currentNode.kind)) { ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.Constructor]).has(currentNode.kind)) {
return true; return true;
}
return currentNode.parameters && currentNode.parameters.length > 0;
} }
return currentNode.parameters && currentNode.parameters.length > 0;
}
); );
// 'returns' // 'returns'
legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, legalityCheck(node, comments, [ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature], ['returns'], true, checkInfoMap, ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature], ['returns'], true, checkInfoMap,
(currentNode, checkResult) => { (currentNode, checkResult) => {
if (!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, if (!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) { ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) {
return false; return false;
} }
return !(!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature, return !(!checkResult && !new Set([ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.MethodSignature,
ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) && (currentNode.type ts.SyntaxKind.MethodDeclaration, ts.SyntaxKind.CallSignature]).has(currentNode.kind)) && (currentNode.type
&& currentNode.type.kind !== ts.SyntaxKind.VoidKeyword); && currentNode.type.kind !== ts.SyntaxKind.VoidKeyword);
} }
); );
// 'useinstead' // 'useinstead'
legalityCheck(node, comments, commentNodeWhiteList, ['useinstead'], true, checkInfoMap, legalityCheck(node, comments, commentNodeWhiteList, ['useinstead'], true, checkInfoMap,
@ -244,11 +244,7 @@ function checkTagValue(tag, index, node, fileName, errorLogs) {
} }
} }
function checkJsDocOfCurrentNode(node, sourcefile, permissionConfigPath, fileName) { function checkJsDocOfCurrentNode(node, sourcefile, fileName) {
let { permissionFile } = require('./utils');
if (permissionConfigPath && fs.existsSync(permissionConfigPath)) {
permissionFile = permissionConfigPath;
}
const checkInfoArray = []; const checkInfoArray = [];
const comments = parseJsDoc(node); const comments = parseJsDoc(node);
const checkInfoMap = checkJsDocLegality(node, comments, {}); const checkInfoMap = checkJsDocLegality(node, comments, {});
@ -281,8 +277,8 @@ function checkJsDocOfCurrentNode(node, sourcefile, permissionConfigPath, fileNam
} }
exports.checkJsDocOfCurrentNode = checkJsDocOfCurrentNode; exports.checkJsDocOfCurrentNode = checkJsDocOfCurrentNode;
function checkJSDoc(node, sourcefile, permissionConfigPath, fileName) { function checkJSDoc(node, sourcefile, fileName) {
const verificationResult = checkJsDocOfCurrentNode(node, sourcefile, permissionConfigPath, fileName); const verificationResult = checkJsDocOfCurrentNode(node, sourcefile, fileName);
let isMissingTagWhitetFile = true; let isMissingTagWhitetFile = true;
let isIllegalTagWhitetFile = true; let isIllegalTagWhitetFile = true;