mirror of
https://gitee.com/openharmony/interface_sdk-js
synced 2024-11-23 07:10:52 +00:00
fix code check
Signed-off-by: wangcaoyu <wangcaoyu@huawei.com>
This commit is contained in:
parent
92cfffaff4
commit
aa98aa6ea1
@ -42,7 +42,6 @@ describe('diffSingleFile', function () {
|
||||
const resultFileContent = fs.readFileSync(resultFilePath, 'utf-8').replace(/\n|\r|\s/g, '');
|
||||
const expectContent = fs.readFileSync(expectFilePath, 'utf-8').replace(/\n|\r|\s/g, '');
|
||||
expect(resultFileContent).to.be.equal(expectContent);
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ function getMdFiles(url, isTestCase) {
|
||||
if (!pathElements.has('build-tools') || isTestCase) {
|
||||
mdFiles.push(filePath);
|
||||
}
|
||||
})
|
||||
});
|
||||
return mdFiles;
|
||||
}
|
||||
|
||||
|
@ -176,16 +176,13 @@ function checkCurrentJSDocChange(newNodeJSDocs, statusCode, node) {
|
||||
checkJSDocChange('permission', currentJSDoc, lastJSDoc, (newTagValue, oldTagValue, addTags) => {
|
||||
let checkResult = true;
|
||||
// 从无到有新增权限
|
||||
if (newTagValue.length === 1 && oldTagValue.length === 0) {
|
||||
checkResult = false;
|
||||
}
|
||||
checkResult = !(newTagValue.length === 1 && oldTagValue.length === 0);
|
||||
// 权限值变更
|
||||
if (newTagValue.length === 1 && oldTagValue.length === 1) {
|
||||
const newPermission = newTagValue[0];
|
||||
const oldPermission = oldTagValue[0];
|
||||
if (newPermission !== oldPermission && checkPermissionChange(newPermission, oldPermission)) {
|
||||
checkResult = false;
|
||||
}
|
||||
checkResult = checkResult &&
|
||||
!(newPermission !== oldPermission && checkPermissionChange(newPermission, oldPermission));
|
||||
}
|
||||
|
||||
if (!checkResult) {
|
||||
@ -305,15 +302,7 @@ function checkHistoryParameters(currentParameters, lastParameters, change) {
|
||||
});
|
||||
// 变更后参数范围大于等于变更前
|
||||
} else if (currentParamType.length >= historyParamType.length) {
|
||||
for (let j = 0; j < historyParamType.length; j++) {
|
||||
if (!new Set(currentParamType).has(historyParamType[j])) {
|
||||
changeErrors.push({
|
||||
node: change.newNode,
|
||||
errorInfo: ErrorValueInfo.ERROR_CHANGES_API_HISTORY_PARAM_TYPE_CHANGE,
|
||||
LogType: LogType.LOG_API,
|
||||
});
|
||||
}
|
||||
}
|
||||
checkHistoryParametersType(historyParamType, currentParamType, changeErrors, change);
|
||||
// 变更后参数范围小于变更前
|
||||
} else {
|
||||
changeErrors.push({
|
||||
@ -341,6 +330,18 @@ function checkHistoryParameters(currentParameters, lastParameters, change) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkHistoryParametersType(historyParamType, currentParamType, changeErrors, change) {
|
||||
for (let j = 0; j < historyParamType.length; j++) {
|
||||
if (!new Set(currentParamType).has(historyParamType[j])) {
|
||||
changeErrors.push({
|
||||
node: change.newNode,
|
||||
errorInfo: ErrorValueInfo.ERROR_CHANGES_API_HISTORY_PARAM_TYPE_CHANGE,
|
||||
LogType: LogType.LOG_API,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查API接口新增参数
|
||||
* @param {array} parameters 新增参数列表
|
||||
|
@ -172,12 +172,11 @@ function checkEventSubscription(node, sourcefile, fileName) {
|
||||
// if the node is method or function
|
||||
if (ts.isFunctionDeclaration(childNode) || ts.isMethodDeclaration(childNode) || ts.isMethodSignature(childNode)) {
|
||||
// if the version needed to be check
|
||||
let childNodeName = '';
|
||||
if (childNode.name && ts.isIdentifier(childNode.name)) {
|
||||
childNodeName = childNode.name.getText();
|
||||
}
|
||||
handleVariousEventSubscriptionAPI(childNode, childNodeName, sourcefile, fileName, onEventAllNames, onEventCheckNames, offEventAllNames,
|
||||
offEventCheckNames, offEventNodes);
|
||||
let childNodeName = (childNode.name && ts.isIdentifier(childNode.name)) ?
|
||||
childNode.name.getText() :
|
||||
'';
|
||||
handleVariousEventSubscriptionAPI(childNode, childNodeName, sourcefile, fileName, onEventAllNames,
|
||||
onEventCheckNames, offEventAllNames, offEventCheckNames, offEventNodes);
|
||||
}
|
||||
});
|
||||
// check the callback parameter of off function is optional
|
||||
|
@ -44,12 +44,13 @@ function checkAllUppercaseHump(word) {
|
||||
}
|
||||
|
||||
function getName(node) {
|
||||
let str = '';
|
||||
if (node.name.escapedText) {
|
||||
return node.name.escapedText.toString();
|
||||
str = node.name.escapedText.toString();
|
||||
} else if (node.name.text) {
|
||||
return node.name.text.toString();
|
||||
str = node.name.text.toString();
|
||||
}
|
||||
return;
|
||||
return str;
|
||||
}
|
||||
|
||||
function isConstantDecorator(node, name) {
|
||||
|
@ -48,7 +48,7 @@ function checkApiNaming(node, sourcefile, fileName) {
|
||||
const lowIdentifier = node.getText().toLowerCase();
|
||||
const apiParentKind = [];
|
||||
getParentkind(node, apiParentKind);
|
||||
if (node.parent.kind === ts.SyntaxKind.TypeReference|| apiParentKind.includes('JSDoc')) {
|
||||
if (node.parent.kind === ts.SyntaxKind.TypeReference || apiParentKind.includes('JSDoc')) {
|
||||
return;
|
||||
}
|
||||
checkApiNamingWords(node, sourcefile, fileName, lowIdentifier);
|
||||
|
@ -99,11 +99,11 @@ function checkMarkError(node, errorMessage, baseFileName) {
|
||||
|
||||
function getParentkind(node, parentkindArr) {
|
||||
if (ts.isSourceFile(node)) {
|
||||
return parentkindArr;
|
||||
return;
|
||||
}
|
||||
if (ts.isSourceFile(node.parent)) {
|
||||
parentkindArr.push(Object.keys(ts.SyntaxKind).find(k => ts.SyntaxKind[k] === node.parent.kind));
|
||||
return parentkindArr;
|
||||
return;
|
||||
}
|
||||
if (!ts.isModuleBlock(node.parent)) {
|
||||
parentkindArr.push(Object.keys(ts.SyntaxKind).find(k => ts.SyntaxKind[k] === node.parent.kind));
|
||||
@ -116,39 +116,41 @@ exports.getParentkind = getParentkind;
|
||||
|
||||
function parseUnicodeConfig() {
|
||||
let maskInfos = '';
|
||||
if (fs.existsSync(path.resolve(__dirname, '../config/errorMaskWhiteList.txt'))) {
|
||||
const maskInformations = fs.readFileSync(path.resolve(__dirname, '../config/errorMaskWhiteList.txt'), 'utf-8');
|
||||
let maskInfoString = '';
|
||||
if (maskInformations && maskInformations.indexOf("\\u") !== -1) {
|
||||
let valArr = maskInformations.split("\\u");
|
||||
for (var j = 0; j < valArr.length; j++) {
|
||||
if (valArr[j] === '') {
|
||||
continue;
|
||||
}
|
||||
maskInfoString += String.fromCharCode(parseInt(valArr[j], 16));
|
||||
}
|
||||
}
|
||||
maskInfos = JSON.parse(maskInfoString);
|
||||
if (!fs.existsSync(path.resolve(__dirname, '../config/errorMaskWhiteList.txt'))) {
|
||||
return maskInfos;
|
||||
}
|
||||
const maskInformations = fs.readFileSync(path.resolve(__dirname, '../config/errorMaskWhiteList.txt'), 'utf-8');
|
||||
let maskInfoString = '';
|
||||
if (maskInformations && maskInformations.indexOf('\\u') === -1) {
|
||||
return JSON.parse(maskInfoString);
|
||||
}
|
||||
let valArr = maskInformations.split('\\u');
|
||||
for (let j = 0; j < valArr.length; j++) {
|
||||
if (valArr[j] === '') {
|
||||
continue;
|
||||
}
|
||||
maskInfoString += String.fromCharCode(parseInt(valArr[j], 16));
|
||||
}
|
||||
maskInfos = JSON.parse(maskInfoString);
|
||||
return maskInfos;
|
||||
}
|
||||
|
||||
function string2unicode() {
|
||||
const str = fs.readFileSync('../test/errorlist.json', 'utf-8');
|
||||
var ret = "";
|
||||
var ustr = "";
|
||||
let ret = '';
|
||||
let ustr = '';
|
||||
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var code = str.charCodeAt(i);
|
||||
var code16 = code.toString(16);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
let code = str.charCodeAt(i);
|
||||
let code16 = code.toString(16);
|
||||
if (code < 0xf) {
|
||||
ustr = "\\u" + "000" + code16;
|
||||
ustr = '\\u' + '000' + code16;
|
||||
} else if (code < 0xff) {
|
||||
ustr = "\\u" + "00" + code16;
|
||||
ustr = '\\u' + '00' + code16;
|
||||
} else if (code < 0xfff) {
|
||||
ustr = "\\u" + "0" + code16;
|
||||
ustr = '\\u' + '0' + code16;
|
||||
} else {
|
||||
ustr = "\\u" + code16;
|
||||
ustr = '\\u' + code16;
|
||||
}
|
||||
ret += ustr;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ const commentNodeWhiteList = [
|
||||
exports.commentNodeWhiteList = commentNodeWhiteList;
|
||||
|
||||
const tagsArrayOfOrder = [
|
||||
'namespace', 'struct', 'extends', "implements", 'typedef', 'interface', 'permission', 'enum', 'constant', 'type',
|
||||
'namespace', 'struct', 'extends', 'implements', 'typedef', 'interface', 'permission', 'enum', 'constant', 'type',
|
||||
'param', 'default', 'returns', 'readonly', 'throws', 'static', 'fires', 'syscap', 'systemapi', 'famodelonly',
|
||||
'FAModelOnly', 'stagemodelonly', 'StageModelOnly', 'crossplatform', 'form', 'atomicservice', 'since', 'deprecated',
|
||||
'useinstead', 'test', 'form', 'example'
|
||||
|
@ -98,13 +98,17 @@ function collectAllApiDiffs(newApiMap, oldApiMap, diffReporter, oldDir, newDir)
|
||||
});
|
||||
});
|
||||
newApiMap.forEach((newPackageMap, _) => {
|
||||
newPackageMap.forEach((newClassMap, _) => {
|
||||
newClassMap.children.forEach((apisMap, _) => {
|
||||
apisMap.forEach((apis, _) => {
|
||||
diffReporter.addNewApi(apis[0], getSycap(apis[0]));
|
||||
const diffInfo = formatDiffInfo(apis[0], StatusCode.NEW_API, '', apis[0].getRawText(), '', apis[0].node, getSycap(apis[0]));
|
||||
diffReporter.addDiffInfo(diffInfo);
|
||||
});
|
||||
collectAllApiDiffFromPackageMap(newPackageMap, diffReporter);
|
||||
});
|
||||
}
|
||||
|
||||
function collectAllApiDiffFromPackageMap(newPackageMap, diffReporter) {
|
||||
newPackageMap.forEach((newClassMap, _) => {
|
||||
newClassMap.children.forEach((apisMap, _) => {
|
||||
apisMap.forEach((apis, _) => {
|
||||
diffReporter.addNewApi(apis[0], getSyscap(apis[0]));
|
||||
const diffInfo = formatDiffInfo(apis[0], StatusCode.NEW_API, '', apis[0].getRawText(), '', apis[0].node, getSyscap(apis[0]));
|
||||
diffReporter.addDiffInfo(diffInfo);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -123,14 +127,7 @@ function collectApiDiffFromPackageMap(oldPackageMap, packageName, newApiMap, ext
|
||||
// dts文件删除
|
||||
let dtsPath;
|
||||
oldPackageMap.forEach((classNameMap, _) => {
|
||||
classNameMap.children.forEach((apisMap, _) => {
|
||||
apisMap.forEach((apis, _) => {
|
||||
ext.diffReporter.addDeletedApi(apis[0], getSycap(apis[0]));
|
||||
const diffInfo = formatDiffInfo(apis[0], StatusCode.DELETE, apis[0].getRawText(), '',
|
||||
apis[0].node, '', getSycap(apis[0]));
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
});
|
||||
});
|
||||
collectApiDiffFromPackageMapClass(classNameMap, ext);
|
||||
dtsPath = classNameMap.type.path;
|
||||
});
|
||||
ext.diffReporter.addDeletedPackage(packageName, dtsPath);
|
||||
@ -143,7 +140,18 @@ function collectApiDiffFromPackageMap(oldPackageMap, packageName, newApiMap, ext
|
||||
}
|
||||
}
|
||||
|
||||
function getSycap(api) {
|
||||
function collectApiDiffFromPackageMapClass(classNameMap, ext) {
|
||||
classNameMap.children.forEach((apisMap, _) => {
|
||||
apisMap.forEach((apis, _) => {
|
||||
ext.diffReporter.addDeletedApi(apis[0], getSyscap(apis[0]));
|
||||
const diffInfo = formatDiffInfo(apis[0], StatusCode.DELETE, apis[0].getRawText(), '',
|
||||
apis[0].node, '', getSyscap(apis[0]));
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSyscap(api) {
|
||||
let curApi = api;
|
||||
let syscap = '';
|
||||
if (api.packageName === 'ArkUI') {
|
||||
@ -175,10 +183,10 @@ function getSycap(api) {
|
||||
if (/\@syscap\s*((\w|\.|\/|\{|\@|\}|\s)+)/g.test(fileContent)) {
|
||||
fileContent.replace(/\@syscap\s*((\w|\.|\/|\{|\@|\}|\s)+)/g, sysCapInfo => {
|
||||
syscap = sysCapInfo.replace(/\@syscap/g, '').trim();
|
||||
})
|
||||
});
|
||||
}
|
||||
return syscap;
|
||||
}
|
||||
return syscap;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,13 +209,13 @@ function collectApiDiffFromClassMap(oldClassApi, className, newPackageMap, ext)
|
||||
newMessage: '',
|
||||
oldNode: '',
|
||||
newNode: '',
|
||||
syscap: getSycap(oldClassApi.type),
|
||||
syscap: getSyscap(oldClassApi.type),
|
||||
});
|
||||
oldClassApi.children.forEach((apisMap, _) => {
|
||||
apisMap.forEach((apis, _) => {
|
||||
ext.diffReporter.addDeletedApi(apis[0], getSycap(apis[0]));
|
||||
ext.diffReporter.addDeletedApi(apis[0], getSyscap(apis[0]));
|
||||
const diffInfo = formatDiffInfo(apis[0], StatusCode.DELETE, apis[0].getRawText(), '',
|
||||
apis[0].node, '', getSycap(apis[0]));
|
||||
apis[0].node, '', getSyscap(apis[0]));
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
});
|
||||
});
|
||||
@ -232,7 +240,7 @@ function collectApiDiffFromApiNameMap(oldSignatureMap, apiName, newClassMap, ext
|
||||
if (!newClassMap.has(apiName)) {
|
||||
// 方法被删除
|
||||
oldSignatureMap.forEach((oldApis, _) => {
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSycap(oldApis[0]));
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSyscap(oldApis[0]));
|
||||
});
|
||||
} else {
|
||||
const newSignatureMap = newClassMap.get(apiName);
|
||||
@ -244,12 +252,12 @@ function collectApiDiffFromApiNameMap(oldSignatureMap, apiName, newClassMap, ext
|
||||
|
||||
sameSignatureSet.forEach(sameSignature => {
|
||||
oldSignatureMap.delete(sameSignature);
|
||||
})
|
||||
});
|
||||
|
||||
oldSignatureMap.forEach((oldApis, _) => {
|
||||
if (newSignatureMap.size === 0) {
|
||||
// 同名函数,方法被删除
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSycap(oldApis[0]));
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSyscap(oldApis[0]));
|
||||
} else {
|
||||
getFunctionDiff(oldApis, newSignatureMap, ext, sameApiNameNumber);
|
||||
}
|
||||
@ -306,7 +314,7 @@ function getFunctionDiff(oldApis, newClassMap, ext, sameApiNameNumber) {
|
||||
if (sameApiNameNumber === 1) {
|
||||
newClassMap.forEach((apiDigestInfo, apiSignautre) => {
|
||||
const diffInfo = formatDiffInfo(oldApis[0], StatusCode.FUNCTION_CHANGES, oldApis[0].getRawText(), apiDigestInfo[0].getRawText(),
|
||||
oldApis[0].node, apiDigestInfo[0].node, getSycap(apiDigestInfo[0]));
|
||||
oldApis[0].node, apiDigestInfo[0].node, getSyscap(apiDigestInfo[0]));
|
||||
ext.diffReporter.addChangedApi(diffInfo);
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
collectJSDocDiffs(oldApis[0], apiDigestInfo[0], ext.diffReporter);
|
||||
@ -317,16 +325,16 @@ function getFunctionDiff(oldApis, newClassMap, ext, sameApiNameNumber) {
|
||||
let newApiTypeMap = new Map();
|
||||
getEveryNewApiType(newClassMap, newApiTypeMap);
|
||||
if (newApiTypeMap.get(oldApiType) !== undefined && newApiTypeMap.get(oldApiType).size > 1) {
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSycap(oldApis[0]));
|
||||
ext.diffReporter.addDeletedApi(oldApis[0], getSyscap(oldApis[0]));
|
||||
const diffInfo = formatDiffInfo(oldApis[0], StatusCode.DELETE, oldApis[0].getRawText(), '',
|
||||
oldApis[0].node, '', getSycap(oldApis[0]));
|
||||
oldApis[0].node, '', getSyscap(oldApis[0]));
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
} else if (newApiTypeMap.get(oldApiType) !== undefined && newApiTypeMap.get(oldApiType).size === 1) {
|
||||
const oldMessage = oldApis[0].getRawText();
|
||||
const newApi = newClassMap.get(...newApiTypeMap.get(oldApiType))[0];
|
||||
const newMessage = newApi.getRawText();
|
||||
const newNode = newApi.node;
|
||||
const syscap = getSycap(newClassMap.get(...newApiTypeMap.get(oldApiType))[0]);
|
||||
const syscap = getSyscap(newClassMap.get(...newApiTypeMap.get(oldApiType))[0]);
|
||||
const diffInfo = formatDiffInfo(oldApis[0], StatusCode.FUNCTION_CHANGES, oldMessage, newMessage, oldApis[0].node, newNode, syscap);
|
||||
ext.diffReporter.addChangedApi(diffInfo);
|
||||
ext.diffReporter.addDiffInfo(diffInfo);
|
||||
|
@ -265,19 +265,20 @@ function mergeDiffsAndChangelogs(changelogs, diffs) {
|
||||
if (diffsData) {
|
||||
diffs.set(dataSignature, addChangelogLink(data, diffsData, diffs));
|
||||
changelogs.delete(dataSignature);
|
||||
} else {
|
||||
data.forEach(changelogData => {
|
||||
const newApiSignature = getSignature(changelogData.newDtsName, changelogData.newApi);
|
||||
const diffsData = diffs.get(newApiSignature);
|
||||
if (!diffsData) {
|
||||
return;
|
||||
}
|
||||
diffsData.forEach(diffData => {
|
||||
diffData.changelog.add(changelogData.changelog);
|
||||
});
|
||||
changelogs.delete(dataSignature);
|
||||
return;
|
||||
}
|
||||
data.forEach(changelogData => {
|
||||
const newApiSignature = getSignature(changelogData.newDtsName, changelogData.newApi);
|
||||
const diffsData = diffs.get(newApiSignature);
|
||||
if (!diffsData) {
|
||||
return;
|
||||
}
|
||||
diffsData.forEach(diffData => {
|
||||
diffData.changelog.add(changelogData.changelog);
|
||||
});
|
||||
}
|
||||
changelogs.delete(dataSignature);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
changelogs.forEach((changelogData, signature) => {
|
||||
|
@ -17,7 +17,7 @@ const ts = require('typescript');
|
||||
const { ApiDigestInfo } = require('./api_data');
|
||||
const { DiffReporter } = require('./reporter');
|
||||
const { StatusCode } = require('./reporter');
|
||||
const { getCheckApiVersion } = require('../../api_check_plugin/src/utils')
|
||||
const { getCheckApiVersion } = require('../../api_check_plugin/src/utils');
|
||||
|
||||
class TagItem {
|
||||
constructor() { }
|
||||
@ -266,16 +266,16 @@ function compareJSDocs(oldApi, newApi, diffReporter) {
|
||||
}
|
||||
|
||||
function getLatestVersion(jsdocs) {
|
||||
let apiLatestVersion = '';
|
||||
if (!jsdocs || jsdocs.length === 0) {
|
||||
return;
|
||||
return apiLatestVersion;
|
||||
}
|
||||
const jsdoc = jsdocs[jsdocs.length - 1];
|
||||
let apiLatestVersion = '';
|
||||
jsdoc.tags?.forEach(tagObject => {
|
||||
if (tagObject.tag === 'since') {
|
||||
apiLatestVersion = tagObject.name;
|
||||
}
|
||||
})
|
||||
});
|
||||
return apiLatestVersion;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ describe('diffSingleFile', function () {
|
||||
const expectContent = fs.readFileSync(expectFilePath, 'utf-8').replace(/\n|\r|\s/g, '');
|
||||
expect(resultFileContent).to.be.equal(expectContent);
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -83,25 +83,32 @@ class ProgramFactory {
|
||||
return (moduleNames, containingFile, reusedNames, redirectedReference, options) => {
|
||||
const resolvedModules = [];
|
||||
for (const moduleName of moduleNames) {
|
||||
const moduleLookupLocaton = ts.resolveModuleName(moduleName, containingFile, options, {
|
||||
fileExists: (fileName) => {
|
||||
return fileName && ts.sys.fileExists(fileName);
|
||||
},
|
||||
readFile: (fileName) => {
|
||||
ts.sys.readFile(fileName);
|
||||
},
|
||||
});
|
||||
const moduleLookupLocaton = ts.resolveModuleName(moduleName, containingFile, options,
|
||||
moduleLookupResolutionHost);
|
||||
if (moduleLookupLocaton.resolvedModule) {
|
||||
resolvedModules.push(moduleLookupLocaton.resolvedModule);
|
||||
} else {
|
||||
const modulePath = moduleResolver.resolveModuleName(moduleName);
|
||||
const resolved = modulePath && ts.sys.fileExists(modulePath) ? { resolvedFileName: modulePath } : undefined;
|
||||
const resolved = modulePath && ts.sys.fileExists(modulePath) ?
|
||||
{ resolvedFileName: modulePath } :
|
||||
undefined;
|
||||
resolvedModules.push(resolved);
|
||||
}
|
||||
}
|
||||
return resolvedModules;
|
||||
};
|
||||
}
|
||||
|
||||
moduleLookupResolutionHost() {
|
||||
return {
|
||||
fileExists: (fileName) => {
|
||||
return fileName && ts.sys.fileExists(fileName);
|
||||
},
|
||||
readFile: (fileName) => {
|
||||
ts.sys.readFile(fileName);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ApiCollector {
|
||||
|
@ -208,8 +208,9 @@ class SystemApiRecognizer {
|
||||
* @returns {ApiDeclarationInformation | undefined} apiDecInfo
|
||||
*/
|
||||
recognizeApiWithNode(node, fileName, positionCallback, useDeclarations) {
|
||||
let finallySymbol = undefined;
|
||||
if (!node) {
|
||||
return undefined;
|
||||
return finallySymbol;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -217,11 +218,11 @@ class SystemApiRecognizer {
|
||||
if (symbol && symbol.flags === ts.SymbolFlags.Alias) {
|
||||
symbol = this.typeChecker.getAliasedSymbol(symbol);
|
||||
}
|
||||
return this.recognizeApiWithNodeAndSymbol(node, symbol, fileName, positionCallback, useDeclarations);
|
||||
finallySymbol = this.recognizeApiWithNodeAndSymbol(node, symbol, fileName, positionCallback, useDeclarations);
|
||||
} catch (error) {
|
||||
Logger.error('UNKNOW NODE', error);
|
||||
}
|
||||
|
||||
return finallySymbol;
|
||||
}
|
||||
|
||||
recognizeApiWithNodeAndSymbol(node, symbol, fileName, positionCallback, useDeclarations) {
|
||||
@ -300,18 +301,19 @@ class SystemApiRecognizer {
|
||||
const parameters = apiDecInfo ? apiDecInfo.apiNode.parameters : undefined;
|
||||
args.forEach((arg, index) => {
|
||||
// interface 定义作为函数入参时, 统计为API
|
||||
if (parameters && parameters[index] && parameters[index].type) {
|
||||
const paramType = parameters[index].type;
|
||||
if (ts.isTypeReferenceNode(paramType)) {
|
||||
const paramTypeApiDecInfo = this.recognizeApiWithNode(paramType.typeName, fileName, (node) => node.getStart(), true);
|
||||
if (paramTypeApiDecInfo) {
|
||||
this.modifyTypeReferenceSourceFileName(paramType.typeName, paramTypeApiDecInfo);
|
||||
paramTypeApiDecInfo.setApiType('interface');
|
||||
paramTypeApiDecInfo.setPosition(ts.getLineAndCharacterOfPosition(arg.getSourceFile(), arg.getStart()));
|
||||
}
|
||||
this.recognizeArgument(arg, fileName);
|
||||
if (!(parameters && parameters[index] && parameters[index].type)) {
|
||||
return;
|
||||
}
|
||||
const paramType = parameters[index].type;
|
||||
if (ts.isTypeReferenceNode(paramType)) {
|
||||
const paramTypeApiDecInfo = this.recognizeApiWithNode(paramType.typeName, fileName, (node) => node.getStart(), true);
|
||||
if (paramTypeApiDecInfo) {
|
||||
this.modifyTypeReferenceSourceFileName(paramType.typeName, paramTypeApiDecInfo);
|
||||
paramTypeApiDecInfo.setApiType('interface');
|
||||
paramTypeApiDecInfo.setPosition(ts.getLineAndCharacterOfPosition(arg.getSourceFile(), arg.getStart()));
|
||||
}
|
||||
}
|
||||
this.recognizeArgument(arg, fileName);
|
||||
});
|
||||
}
|
||||
|
||||
@ -689,23 +691,31 @@ class SystemApiRecognizer {
|
||||
return;
|
||||
}
|
||||
if (!typeSymbol && childSymbol.members) {
|
||||
childSymbol.members.forEach((memberSymbol, memberName) => {
|
||||
heritageMembers.set(memberName, memberSymbol);
|
||||
});
|
||||
setHeritageMembersFroMmembers(heritageMembers, childSymbol.members);
|
||||
return;
|
||||
}
|
||||
const valueDeclaration = typeSymbol.valueDeclaration;
|
||||
if (!valueDeclaration || !this.isSdkApi(valueDeclaration.getSourceFile().fileName)) {
|
||||
return;
|
||||
}
|
||||
typeSymbol.members.forEach((memberSymbol, memberName) => {
|
||||
heritageMembers.set(memberName, memberSymbol);
|
||||
});
|
||||
setHeritageMembersFroMmembers(heritageMembers, typeSymbol.members);
|
||||
});
|
||||
});
|
||||
return heritageMembers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜集所有父类(属于SDK中的API)的方法和属性。
|
||||
*
|
||||
* @param {Map} heritageMembers
|
||||
* @param {ts.NodeArray} members
|
||||
*/
|
||||
setHeritageMembersFroMmembers(heritageMembers, members) {
|
||||
members.forEach((memberSymbol, memberName) => {
|
||||
heritageMembers.set(memberName, memberSymbol);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析属性访问
|
||||
*
|
||||
|
@ -235,7 +235,7 @@ class Sdk {
|
||||
listDtsFiles(dir, dest) {
|
||||
const sdkRoot = this.getPath();
|
||||
if (!sdkRoot) {
|
||||
return new Set();
|
||||
return;
|
||||
}
|
||||
const subDir = path.resolve(sdkRoot, dir);
|
||||
FileSystem.listFiles(subDir, (filePath) => path.basename(filePath).endsWith('.d.ts'), dest);
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"ets": {
|
||||
"ets": {
|
||||
"render": {
|
||||
"method": ["build", "pageTransition"],
|
||||
"decorator": "Builder"
|
||||
|
@ -184,7 +184,7 @@ function processKitImportDeclaration(statement, needDeleteMap, needDeleteExportN
|
||||
*/
|
||||
function hasFileByImportPath(importPath) {
|
||||
let fileDir = path.resolve(apiSourcePath);
|
||||
if (importPath.startsWith("@arkts")) {
|
||||
if (importPath.startsWith('@arkts')) {
|
||||
fileDir = path.resolve(apiSourcePath, '../arkts');
|
||||
}
|
||||
const flag = ['.d.ts', '.d.ets'].some(ext => {
|
||||
|
@ -15,7 +15,7 @@
|
||||
import ExcelJS from 'exceljs';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { execSync } from "child_process";
|
||||
import { execSync } from 'child_process';
|
||||
import { EnumUtils } from '../utils/EnumUtils';
|
||||
import { FileUtils } from '../utils/FileUtils';
|
||||
import { LogUtil } from '../utils/logUtil';
|
||||
@ -263,26 +263,10 @@ function collectApiCallback(apiData: ApiStatisticsInfo[], sheet: ExcelJS.Workshe
|
||||
const subsystemMap: Map<string, string> = FunctionUtils.readSubsystemFile().subsystemMap;
|
||||
sheet.name = 'JsApi';
|
||||
sheet.views = [{ xSplit: 1 }];
|
||||
sheet.getRow(1).values = [
|
||||
'模块名',
|
||||
'类名',
|
||||
'方法名',
|
||||
'函数',
|
||||
'类型',
|
||||
'起始版本',
|
||||
'废弃版本',
|
||||
'syscap',
|
||||
'错误码',
|
||||
'是否为系统API',
|
||||
'模型限制',
|
||||
'权限',
|
||||
'是否支持跨平台',
|
||||
'是否支持卡片应用',
|
||||
'是否为高阶API',
|
||||
'装饰器',
|
||||
'kit',
|
||||
'文件路径',
|
||||
'子系统',
|
||||
sheet.getRow(1).values = ['模块名', '类名', '方法名', '函数', '类型',
|
||||
'起始版本', '废弃版本', 'syscap', '错误码', '是否为系统API',
|
||||
'模型限制', '权限', '是否支持跨平台', '是否支持卡片应用', '是否为高阶API',
|
||||
'装饰器', 'kit', '文件路径', '子系统',
|
||||
];
|
||||
let lineNumber = 2;
|
||||
apiData.forEach((apiInfo: ApiStatisticsInfo) => {
|
||||
@ -290,7 +274,6 @@ function collectApiCallback(apiData: ApiStatisticsInfo[], sheet: ExcelJS.Workshe
|
||||
if (apiRelationsSet.has(apiRelations)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sheet.getRow(lineNumber).values = [
|
||||
apiInfo.getPackageName(),
|
||||
apiInfo.getParentModuleName(),
|
||||
@ -328,7 +311,7 @@ function checkApi(options: OptionObjType): ToolNameValueType {
|
||||
let fileContent: ApiResultMessage[] = [];
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
|
||||
fileContent = LocalEntry.checkEntryLocal([], [], "", 'false');
|
||||
fileContent = LocalEntry.checkEntryLocal([], [], '', 'false');
|
||||
} else if (process.env.NODE_ENV === 'production') {
|
||||
}
|
||||
let finalData: (string | ApiResultMessage)[] = [];
|
||||
@ -355,7 +338,7 @@ function checkApi(options: OptionObjType): ToolNameValueType {
|
||||
* @return { ToolNameValueType }
|
||||
*/
|
||||
function checkOnline(options: OptionObjType): ToolNameValueType {
|
||||
options.format = formatType.NULL
|
||||
options.format = formatType.NULL;
|
||||
try {
|
||||
LocalEntry.checkEntryLocal(options.path.split(','), options.checker.split(','), options.output, options.excel);
|
||||
return {
|
||||
@ -365,10 +348,10 @@ function checkOnline(options: OptionObjType): ToolNameValueType {
|
||||
const error = exception as Error;
|
||||
LogUtil.e('error check', error.stack ? error.stack : error.message);
|
||||
} finally {
|
||||
return {
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -412,8 +395,8 @@ function diffApi(options: OptionObjType): ToolNameValueType {
|
||||
}
|
||||
}
|
||||
function detectionApi(options: OptionObjType): ToolNameValueType {
|
||||
process.env.NEED_DETECTION = "true";
|
||||
options.format = formatType.NULL
|
||||
process.env.NEED_DETECTION = 'true';
|
||||
options.format = formatType.NULL;
|
||||
const fileDir: string = path.resolve(FileUtils.getBaseDirName(), options.collectPath);
|
||||
let collectFile: string = '';
|
||||
if (options.collectFile !== '') {
|
||||
@ -447,11 +430,10 @@ function detectionApi(options: OptionObjType): ToolNameValueType {
|
||||
const error = exception as Error;
|
||||
LogUtil.e(`error collect`, error.stack ? error.stack : error.message);
|
||||
} finally {
|
||||
return {
|
||||
data: []
|
||||
}
|
||||
|
||||
}
|
||||
return {
|
||||
data: [],
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -2351,11 +2351,6 @@
|
||||
"androgenic",
|
||||
"androgynous",
|
||||
"androgyny",
|
||||
"android",
|
||||
"androidhive",
|
||||
"androidmanifest",
|
||||
"androidruntime",
|
||||
"androidx",
|
||||
"andromache",
|
||||
"andromeda",
|
||||
"andropov",
|
||||
@ -3901,6 +3896,7 @@
|
||||
"astaire",
|
||||
"astarte",
|
||||
"astatine",
|
||||
"astc",
|
||||
"aster",
|
||||
"asteria",
|
||||
"asterisk",
|
||||
@ -10705,9 +10701,6 @@
|
||||
"chromatograph",
|
||||
"chromatographic",
|
||||
"chromatography",
|
||||
"chrome",
|
||||
"chromedriver",
|
||||
"chromeoptions",
|
||||
"chromic",
|
||||
"chromite",
|
||||
"chromium",
|
||||
@ -14782,7 +14775,6 @@
|
||||
"cystic",
|
||||
"cython",
|
||||
"cytochemistry",
|
||||
"cytochrome",
|
||||
"cytologist",
|
||||
"cytology",
|
||||
"cytolysis",
|
||||
@ -19124,7 +19116,6 @@
|
||||
"eked",
|
||||
"ekg",
|
||||
"ekstrom",
|
||||
"ektachrome",
|
||||
"el",
|
||||
"elaborate",
|
||||
"elaborateness",
|
||||
@ -25798,7 +25789,6 @@
|
||||
"glyphicon",
|
||||
"glyphs",
|
||||
"gm",
|
||||
"gmail",
|
||||
"gmap",
|
||||
"gmaps",
|
||||
"gmp",
|
||||
@ -25983,15 +25973,6 @@
|
||||
"goofiness",
|
||||
"goofy",
|
||||
"goog",
|
||||
"google",
|
||||
"googleapiclient",
|
||||
"googleapis",
|
||||
"googlecode",
|
||||
"googled",
|
||||
"googlemap",
|
||||
"googlemaps",
|
||||
"googlesource",
|
||||
"googleusercontent",
|
||||
"googling",
|
||||
"gooier",
|
||||
"gooiest",
|
||||
@ -34195,7 +34176,6 @@
|
||||
"kobe",
|
||||
"koch",
|
||||
"kochab",
|
||||
"kodachrome",
|
||||
"kodak",
|
||||
"kodaly",
|
||||
"kodiak",
|
||||
@ -34602,7 +34582,6 @@
|
||||
"landowner",
|
||||
"landownership",
|
||||
"landowning",
|
||||
"landroid",
|
||||
"landry",
|
||||
"lands",
|
||||
"landsat",
|
||||
@ -38693,7 +38672,6 @@
|
||||
"merck",
|
||||
"mercurial",
|
||||
"mercuric",
|
||||
"mercurochrome",
|
||||
"mercury",
|
||||
"mercy",
|
||||
"mere",
|
||||
@ -38962,7 +38940,6 @@
|
||||
"mg",
|
||||
"mgm",
|
||||
"mgmt",
|
||||
"mgoogleapiclient",
|
||||
"mgr",
|
||||
"mh",
|
||||
"mhandler",
|
||||
@ -41920,7 +41897,6 @@
|
||||
"nichole",
|
||||
"nicholle",
|
||||
"nicholson",
|
||||
"nichrome",
|
||||
"nick",
|
||||
"nickel",
|
||||
"nickelodeon",
|
||||
@ -47567,7 +47543,6 @@
|
||||
"polybutene",
|
||||
"polycarbonate",
|
||||
"polychemicals",
|
||||
"polychrome",
|
||||
"polyclinic",
|
||||
"polycrystalline",
|
||||
"polyelectrolytes",
|
||||
@ -48385,6 +48360,8 @@
|
||||
"prescription",
|
||||
"prescriptive",
|
||||
"preselect",
|
||||
"preselected",
|
||||
"preselecteduris",
|
||||
"presence",
|
||||
"present",
|
||||
"presentable",
|
||||
@ -68781,7 +68758,6 @@
|
||||
"youths",
|
||||
"youtrack",
|
||||
"youtu",
|
||||
"youtube",
|
||||
"yovonnda",
|
||||
"yow",
|
||||
"yowl",
|
||||
@ -69069,4 +69045,4 @@
|
||||
"zz",
|
||||
"zzz"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export class LocalEntry {
|
||||
return allResult;
|
||||
}
|
||||
|
||||
static maskAlarm(allResultInfo: ApiResultSimpleInfo[], fileRuleArr: string[]) {
|
||||
static maskAlarm(allResultInfo: ApiResultSimpleInfo[], fileRuleArr: string[]): void {
|
||||
const localScan: boolean = (fileRuleArr.length === 1 && fileRuleArr[0] === 'all') ? true : false;
|
||||
const apiCheckInfos: Map<string, string> = new Map(Object.entries({ ...DOC, ...DEFINE, ...CHANEGE }));
|
||||
let apiCheckAdmissiveSet: Set<string> = new Set();
|
||||
@ -53,7 +53,25 @@ export class LocalEntry {
|
||||
}
|
||||
});
|
||||
}
|
||||
const maskResult: ApiResultSimpleInfo[] = allResultInfo.filter((resultItem: ApiResultSimpleInfo) => {
|
||||
const maskResult: ApiResultSimpleInfo[] = LocalEntry.filterAllResultInfo(allResultInfo,
|
||||
apiCheckInfos, apiCheckAdmissiveSet);
|
||||
maskResult.forEach(resultItem => {
|
||||
const apiChecktErrorLog: ApiResultMessage = new ApiResultMessage();
|
||||
apiChecktErrorLog
|
||||
.setFilePath(resultItem.filePath)
|
||||
.setLocation(resultItem.location)
|
||||
.setLevel(resultItem.level)
|
||||
.setType(resultItem.type)
|
||||
.setMessage(resultItem.message)
|
||||
.setMainBuggyCode(resultItem.apiText)
|
||||
.setMainBuggyLine(resultItem.location);
|
||||
apiCheckResult.push(apiChecktErrorLog);
|
||||
});
|
||||
}
|
||||
|
||||
static filterAllResultInfo(allResultInfo: ApiResultSimpleInfo[], apiCheckInfos: Map<string, string>,
|
||||
apiCheckAdmissiveSet: Set<string>): ApiResultSimpleInfo[] {
|
||||
return allResultInfo.filter((resultItem: ApiResultSimpleInfo) => {
|
||||
let resultItemInfo: string = resultItem.message.replace(/API check error of \[.*\]: /g, '');
|
||||
const regex1 = /Prohibited word in \[.*\]:{option}.The word allowed is \[.*\]\./g;
|
||||
const regex2 = /Prohibited word in \[.*\]:{ability} in the \[.*\] file\./g;
|
||||
@ -70,27 +88,21 @@ export class LocalEntry {
|
||||
resultItemInfo = resultItemInfo.replace(/\[.*\]/g, '[XXXX]');
|
||||
}
|
||||
if (apiCheckAdmissiveSet.has(resultItemInfo)) {
|
||||
for (let [key, value] of apiCheckInfos.entries()) {
|
||||
if (value === resultItemInfo)
|
||||
resultItem.setType(key);
|
||||
const key: string = LocalEntry.filterApiCheckInfos(apiCheckInfos, resultItemInfo);
|
||||
if (key !== '') {
|
||||
resultItem.setType(key);
|
||||
}
|
||||
|
||||
}
|
||||
return apiCheckAdmissiveSet.has(resultItemInfo);
|
||||
});
|
||||
maskResult.forEach(resultItem => {
|
||||
const apiChecktErrorLog: ApiResultMessage = new ApiResultMessage();
|
||||
apiChecktErrorLog
|
||||
.setFilePath(resultItem.filePath)
|
||||
.setLocation(resultItem.location)
|
||||
.setLevel(resultItem.level)
|
||||
.setType(resultItem.type)
|
||||
.setMessage(resultItem.message)
|
||||
.setMainBuggyCode(resultItem.apiText)
|
||||
.setMainBuggyLine(resultItem.location);
|
||||
|
||||
apiCheckResult.push(apiChecktErrorLog);
|
||||
})
|
||||
}
|
||||
|
||||
static filterApiCheckInfos(apiCheckInfos: Map<string, string>, resultItemInfo: string): string {
|
||||
for (let [key, value] of apiCheckInfos.entries()) {
|
||||
if (value === resultItemInfo) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -119,160 +119,163 @@ export class Check {
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
} else {
|
||||
// legality check
|
||||
const tagLegalityCheckResult: ErrorTagFormat[] = LegalityCheck.apiLegalityCheck(singleApi, apiJsdoc);
|
||||
// order check
|
||||
const orderCheckResult: ErrorTagFormat = OrderCheck.orderCheck(singleApi, apiJsdoc);
|
||||
// api naming check
|
||||
const namingCheckResult: ErrorTagFormat = ApiNamingCheck.namingCheck(singleApi);
|
||||
// tags name check
|
||||
const tagNamseCheckResult: ErrorTagFormat = TagNameCheck.tagNameCheck(apiJsdoc);
|
||||
// tags inherit check
|
||||
const tagInheritCheckResult: ErrorTagFormat = TagInheritCheck.tagInheritCheck(singleApi);
|
||||
// tags value check
|
||||
const tagValueCheckResult: ErrorTagFormat[] = TagValueCheck.tagValueCheck(singleApi, apiJsdoc);
|
||||
// tags repeat check
|
||||
const tagRepeatCheckResult: ErrorTagFormat[] = TagRepeatCheck.tagRepeatCheck(apiJsdoc);
|
||||
// api forbidden wors check
|
||||
const forbiddenWorsCheckResult: ErrorTagFormat = ForbiddenWordsCheck.forbiddenWordsCheck(singleApi as ClassInfo);
|
||||
if (!orderCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_ORDER_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_ORDER,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
orderCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!tagNamseCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.UNKNOW_DECORATOR_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.UNKNOW_DECORATOR,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
tagNamseCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!forbiddenWorsCheckResult.state) {
|
||||
const isTsFile: boolean = /\.d\.ts/.test(singleApi.getFilePath());
|
||||
const isAnyError: boolean = /any/.test(forbiddenWorsCheckResult.errorInfo);
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.FORBIDDEN_WORDS_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.FORBIDDEN_WORDS,
|
||||
LogType.LOG_API,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
forbiddenWorsCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!namingCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.NAMING_ERRORS_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.NAMING_ERRORS,
|
||||
LogType.LOG_API,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
namingCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!tagInheritCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
tagInheritCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
tagLegalityCheckResult.forEach((legalityResult) => {
|
||||
if (legalityResult.state === false) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
legalityResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
});
|
||||
tagValueCheckResult.forEach((valueResult) => {
|
||||
if (valueResult.state === false) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_VALUE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_VALUE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
valueResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
});
|
||||
tagRepeatCheckResult.forEach((repeatResult) => {
|
||||
if (repeatResult.state === false) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
repeatResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
// legality check
|
||||
const tagLegalityCheckResult: ErrorTagFormat[] = LegalityCheck.apiLegalityCheck(singleApi, apiJsdoc);
|
||||
// order check
|
||||
const orderCheckResult: ErrorTagFormat = OrderCheck.orderCheck(singleApi, apiJsdoc);
|
||||
// api naming check
|
||||
const namingCheckResult: ErrorTagFormat = ApiNamingCheck.namingCheck(singleApi);
|
||||
// tags name check
|
||||
const tagNamseCheckResult: ErrorTagFormat = TagNameCheck.tagNameCheck(apiJsdoc);
|
||||
// tags inherit check
|
||||
const tagInheritCheckResult: ErrorTagFormat = TagInheritCheck.tagInheritCheck(singleApi);
|
||||
// tags value check
|
||||
const tagValueCheckResult: ErrorTagFormat[] = TagValueCheck.tagValueCheck(singleApi, apiJsdoc);
|
||||
// tags repeat check
|
||||
const tagRepeatCheckResult: ErrorTagFormat[] = TagRepeatCheck.tagRepeatCheck(apiJsdoc);
|
||||
// api forbidden wors check
|
||||
const forbiddenWorsCheckResult: ErrorTagFormat = ForbiddenWordsCheck.forbiddenWordsCheck(singleApi as ClassInfo);
|
||||
if (!orderCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_ORDER_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_ORDER,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
orderCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!tagNamseCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.UNKNOW_DECORATOR_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.UNKNOW_DECORATOR,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
tagNamseCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!forbiddenWorsCheckResult.state) {
|
||||
const isTsFile: boolean = /\.d\.ts/.test(singleApi.getFilePath());
|
||||
const isAnyError: boolean = /any/.test(forbiddenWorsCheckResult.errorInfo);
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.FORBIDDEN_WORDS_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.FORBIDDEN_WORDS,
|
||||
LogType.LOG_API,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
forbiddenWorsCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!namingCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.NAMING_ERRORS_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.NAMING_ERRORS,
|
||||
LogType.LOG_API,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
namingCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
if (!tagInheritCheckResult.state) {
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
tagInheritCheckResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
}
|
||||
tagLegalityCheckResult.forEach((legalityResult) => {
|
||||
if (legalityResult.state !== false) {
|
||||
return;
|
||||
}
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
legalityResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
});
|
||||
tagValueCheckResult.forEach((valueResult) => {
|
||||
if (valueResult.state !== false) {
|
||||
return;
|
||||
}
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_VALUE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_VALUE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
valueResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
});
|
||||
tagRepeatCheckResult.forEach((repeatResult) => {
|
||||
if (repeatResult.state !== false) {
|
||||
return;
|
||||
}
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.WRONG_SCENE_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
singleApi.getFilePath(),
|
||||
singleApi.getPos(),
|
||||
ErrorType.WRONG_SCENE,
|
||||
LogType.LOG_JSDOC,
|
||||
toNumber(apiJsdoc.since),
|
||||
singleApi.getApiName(),
|
||||
singleApi.getDefinedText(),
|
||||
repeatResult.errorInfo,
|
||||
compositiveResult,
|
||||
compositiveLocalResult
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
@ -54,7 +54,6 @@ export class ApiChangeCheck {
|
||||
const newSDKApiMap: FilesMap = Parser.parseFile(path.resolve(newFileDir, '..'), newFileDir);
|
||||
diffInfos = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, true);
|
||||
}
|
||||
|
||||
diffInfos.forEach((diffInfo: BasicDiffInfo) => {
|
||||
if (diffInfo.getIsCompatible() !== false) {
|
||||
return;
|
||||
|
@ -53,62 +53,62 @@ export class LegalityCheck {
|
||||
}
|
||||
|
||||
// 判断api的jsdoc中是否存在非法标签,是否缺失必选标签
|
||||
if (Array.isArray(apiLegalityTagsArray)) {
|
||||
const apiTags: Comment.CommentTag[] | undefined = apiJsdoc.tags;
|
||||
if (apiTags === undefined) {
|
||||
const sinceLost: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, ['since']),
|
||||
};
|
||||
const syscapLost: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, ['syscap']),
|
||||
};
|
||||
apiLegalityCheckResult.push(sinceLost, syscapLost);
|
||||
return apiLegalityCheckResult;
|
||||
}
|
||||
|
||||
let paramTagNumber: number = 0;
|
||||
let paramApiNumber: number =
|
||||
singleApi.getApiType() === ApiType.METHOD ? (singleApi as MethodInfo).getParams().length : 0;
|
||||
apiTags.forEach((apiTag) => {
|
||||
paramTagNumber = apiTag.tag === 'param' ? paramTagNumber + 1 : paramTagNumber;
|
||||
const isUseinsteadLegalSituation: boolean = apiTag.tag === 'useinstead' && apiJsdoc.deprecatedVersion !== '-1';
|
||||
|
||||
if (illegalTagsArray.includes(apiTag.tag)) {
|
||||
if (apiTag.tag !== 'useinstead' || !isUseinsteadLegalSituation) {
|
||||
const apiRedundantResultFormat: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_USE, [apiTag.tag]),
|
||||
};
|
||||
apiLegalityCheckResult.push(apiRedundantResultFormat);
|
||||
}
|
||||
}
|
||||
apiLegalityTagsSet.delete('param');
|
||||
if (apiLegalityTagsSet.has(apiTag.tag)) {
|
||||
apiLegalityTagsSet.delete(apiTag.tag);
|
||||
}
|
||||
if (singleApi.getApiType() === ApiType.INTERFACE && (apiTag.tag === 'typedef' || apiTag.tag === 'interface')) {
|
||||
apiLegalityTagsSet.delete('typedef');
|
||||
apiLegalityTagsSet.delete('interface');
|
||||
}
|
||||
if (singleApi.getApiType() === ApiType.METHOD && (singleApi as MethodInfo).getReturnValue().length === 0) {
|
||||
apiLegalityTagsSet.delete('returns');
|
||||
}
|
||||
});
|
||||
// param合法性单独进行校验
|
||||
LegalityCheck.paramLegalityCheck(paramTagNumber, paramApiNumber, apiLegalityCheckResult);
|
||||
// 缺失标签set合集
|
||||
apiLegalityTagsSet.forEach((apiLegalityTag) => {
|
||||
if (!conditionalOptionalTags.includes(apiLegalityTag)) {
|
||||
const apiLostResultFormat: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, [apiLegalityTag]),
|
||||
};
|
||||
apiLegalityCheckResult.push(apiLostResultFormat);
|
||||
}
|
||||
});
|
||||
if (!Array.isArray(apiLegalityTagsArray)) {
|
||||
return apiLegalityCheckResult;
|
||||
}
|
||||
const apiTags: Comment.CommentTag[] | undefined = apiJsdoc.tags;
|
||||
if (apiTags === undefined) {
|
||||
const sinceLost: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, ['since']),
|
||||
};
|
||||
const syscapLost: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, ['syscap']),
|
||||
};
|
||||
apiLegalityCheckResult.push(sinceLost, syscapLost);
|
||||
return apiLegalityCheckResult;
|
||||
}
|
||||
|
||||
let paramTagNumber: number = 0;
|
||||
let paramApiNumber: number =
|
||||
singleApi.getApiType() === ApiType.METHOD ? (singleApi as MethodInfo).getParams().length : 0;
|
||||
apiTags.forEach((apiTag) => {
|
||||
paramTagNumber = apiTag.tag === 'param' ? paramTagNumber + 1 : paramTagNumber;
|
||||
const isUseinsteadLegalSituation: boolean = apiTag.tag === 'useinstead' && apiJsdoc.deprecatedVersion !== '-1';
|
||||
|
||||
if (illegalTagsArray.includes(apiTag.tag) && (apiTag.tag !== 'useinstead' || !isUseinsteadLegalSituation)) {
|
||||
const apiRedundantResultFormat: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_USE, [apiTag.tag]),
|
||||
};
|
||||
apiLegalityCheckResult.push(apiRedundantResultFormat);
|
||||
}
|
||||
apiLegalityTagsSet.delete('param');
|
||||
if (apiLegalityTagsSet.has(apiTag.tag)) {
|
||||
apiLegalityTagsSet.delete(apiTag.tag);
|
||||
}
|
||||
if (singleApi.getApiType() === ApiType.INTERFACE && (apiTag.tag === 'typedef' || apiTag.tag === 'interface')) {
|
||||
apiLegalityTagsSet.delete('typedef');
|
||||
apiLegalityTagsSet.delete('interface');
|
||||
}
|
||||
if (singleApi.getApiType() === ApiType.METHOD && (singleApi as MethodInfo).getReturnValue().length === 0) {
|
||||
apiLegalityTagsSet.delete('returns');
|
||||
}
|
||||
});
|
||||
// param合法性单独进行校验
|
||||
LegalityCheck.paramLegalityCheck(paramTagNumber, paramApiNumber, apiLegalityCheckResult);
|
||||
// 缺失标签set合集
|
||||
apiLegalityTagsSet.forEach((apiLegalityTag) => {
|
||||
if (!conditionalOptionalTags.includes(apiLegalityTag)) {
|
||||
const apiLostResultFormat: ErrorTagFormat = {
|
||||
state: false,
|
||||
errorInfo: CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, [apiLegalityTag]),
|
||||
};
|
||||
apiLegalityCheckResult.push(apiLostResultFormat);
|
||||
}
|
||||
});
|
||||
|
||||
return apiLegalityCheckResult;
|
||||
}
|
||||
|
||||
|
@ -38,85 +38,62 @@ export class TagValueCheck {
|
||||
return tagValueError;
|
||||
}
|
||||
tagsName.forEach((tag) => {
|
||||
if (tag.tag === 'since') {
|
||||
const sincevalueCheckResult = TagValueCheck.sinceTagValueCheck(tag);
|
||||
if (!sincevalueCheckResult.state) {
|
||||
tagValueError.push(sincevalueCheckResult);
|
||||
}
|
||||
let errorTagInfo: ErrorTagFormat = {
|
||||
state: true,
|
||||
errorInfo: '',
|
||||
};
|
||||
switch (tag.tag) {
|
||||
case 'since':
|
||||
errorTagInfo = TagValueCheck.sinceTagValueCheck(tag);
|
||||
break;
|
||||
case 'extends':
|
||||
case 'implements':
|
||||
errorTagInfo = TagValueCheck.extendsTagValueCheck(singleApi, tag);
|
||||
break;
|
||||
case 'enum':
|
||||
errorTagInfo = TagValueCheck.enumTagValueCheck(tag);
|
||||
break;
|
||||
case 'returns':
|
||||
errorTagInfo = TagValueCheck.returnsTagValueCheck(singleApi, tag);
|
||||
break;
|
||||
case 'namespace':
|
||||
case 'typedef':
|
||||
case 'struct':
|
||||
errorTagInfo = TagValueCheck.outerTagValueCheck(singleApi as ClassInfo, tag);
|
||||
break;
|
||||
case 'type':
|
||||
errorTagInfo = TagValueCheck.typeTagValueCheck(singleApi, tag);
|
||||
break;
|
||||
case 'syscap':
|
||||
errorTagInfo = TagValueCheck.syscapTagValueCheck(tag);
|
||||
break;
|
||||
case 'default':
|
||||
errorTagInfo = TagValueCheck.defaultTagValueCheck(tag);
|
||||
break;
|
||||
case 'deprecated':
|
||||
errorTagInfo = TagValueCheck.deprecatedTagValueCheck(tag);
|
||||
break;
|
||||
case 'permission':
|
||||
errorTagInfo = TagValueCheck.permissionTagValueCheck(tag);
|
||||
break;
|
||||
case 'throws':
|
||||
if (singleApi.getLastJsDocInfo()?.deprecatedVersion === '-1') {
|
||||
throwsIndex += 1;
|
||||
errorTagInfo = TagValueCheck.throwsTagValueCheck(tag, throwsIndex, tagsName);
|
||||
}
|
||||
break;
|
||||
case 'param':
|
||||
paramIndex += 1;
|
||||
errorTagInfo = TagValueCheck.paramTagValueCheck(singleApi, tag, paramIndex);
|
||||
break;
|
||||
case 'useinstead':
|
||||
errorTagInfo = TagValueCheck.useinsteadTagValueCheck(tag);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (tag.tag === 'extends' || tag.tag === 'implements') {
|
||||
const extendsvalueCheckResult = TagValueCheck.extendsTagValueCheck(singleApi, tag);
|
||||
if (!extendsvalueCheckResult.state) {
|
||||
tagValueError.push(extendsvalueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'enum') {
|
||||
const enumvalueCheckResult = TagValueCheck.enumTagValueCheck(tag);
|
||||
if (!enumvalueCheckResult.state) {
|
||||
tagValueError.push(enumvalueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'returns') {
|
||||
const returnsvalueCheckResult = TagValueCheck.returnsTagValueCheck(singleApi, tag);
|
||||
if (!returnsvalueCheckResult.state) {
|
||||
tagValueError.push(returnsvalueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'namespace' || tag.tag === 'typedef' || tag.tag === 'struct') {
|
||||
const outerValueCheckResult = TagValueCheck.outerTagValueCheck(singleApi as ClassInfo, tag);
|
||||
if (!outerValueCheckResult.state) {
|
||||
tagValueError.push(outerValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'type') {
|
||||
const typeValueCheckResult = TagValueCheck.typeTagValueCheck(singleApi, tag);
|
||||
if (!typeValueCheckResult.state) {
|
||||
tagValueError.push(typeValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'syscap') {
|
||||
const syscapValueCheckResult = TagValueCheck.syscapTagValueCheck(tag);
|
||||
if (!syscapValueCheckResult.state) {
|
||||
tagValueError.push(syscapValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'default') {
|
||||
const defaultValueCheckResult = TagValueCheck.defaultTagValueCheck(tag);
|
||||
if (!defaultValueCheckResult.state) {
|
||||
tagValueError.push(defaultValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'deprecated') {
|
||||
const deprecatedValueCheckResult = TagValueCheck.deprecatedTagValueCheck(tag);
|
||||
if (!deprecatedValueCheckResult.state) {
|
||||
tagValueError.push(deprecatedValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'permission') {
|
||||
const permissionValueCheckResult = TagValueCheck.permissionTagValueCheck(tag);
|
||||
if (!permissionValueCheckResult.state) {
|
||||
tagValueError.push(permissionValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'throws' && singleApi.getLastJsDocInfo()?.deprecatedVersion === '-1') {
|
||||
throwsIndex += 1;
|
||||
const throwsValueCheckResult = TagValueCheck.throwsTagValueCheck(tag, throwsIndex, tagsName);
|
||||
if (!throwsValueCheckResult.state) {
|
||||
tagValueError.push(throwsValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'param') {
|
||||
paramIndex += 1;
|
||||
const paramValueCheckResult = TagValueCheck.paramTagValueCheck(singleApi, tag, paramIndex);
|
||||
if (!paramValueCheckResult.state) {
|
||||
tagValueError.push(paramValueCheckResult);
|
||||
}
|
||||
}
|
||||
if (tag.tag === 'useinstead') {
|
||||
const useinsteadValueCheckResult = TagValueCheck.useinsteadTagValueCheck(tag);
|
||||
if (!useinsteadValueCheckResult.state) {
|
||||
tagValueError.push(useinsteadValueCheckResult);
|
||||
}
|
||||
if (!errorTagInfo.state) {
|
||||
tagValueError.push(errorTagInfo);
|
||||
}
|
||||
});
|
||||
return tagValueError;
|
||||
@ -200,7 +177,7 @@ export class TagValueCheck {
|
||||
|
||||
let returnsApiValue: string[] = [];
|
||||
if (singleApi.getApiType() !== ApiType.METHOD) {
|
||||
return returnsValueCheckResult
|
||||
return returnsValueCheckResult;
|
||||
}
|
||||
const spacealCase: string[] = CommonFunctions.judgeSpecialCase((singleApi as MethodInfo).returnValueType);
|
||||
if (spacealCase.length > 0) {
|
||||
@ -240,8 +217,8 @@ export class TagValueCheck {
|
||||
const genericArr: GenericInfo[] = singleApi.getGenericInfo();
|
||||
if (genericArr.length > 0) {
|
||||
let genericInfo = genericArr.map((generic) => {
|
||||
return generic.getGenericContent()
|
||||
}).join(',')
|
||||
return generic.getGenericContent();
|
||||
}).join(',');
|
||||
apiValue = apiValue + '<' + genericInfo + '>';
|
||||
}
|
||||
if (singleApi.getApiType() === 'Interface' && tagValue !== apiValue) {
|
||||
@ -410,8 +387,8 @@ export class TagValueCheck {
|
||||
}
|
||||
const allTagName: string[] = [];
|
||||
tagsName?.forEach((tag: Comment.CommentTag) => {
|
||||
allTagName.push(tag.tag)
|
||||
})
|
||||
allTagName.push(tag.tag);
|
||||
});
|
||||
if (throwsTagName === '201' && !allTagName.includes('permission')) {
|
||||
throwsValueCheckResult.state = false;
|
||||
throwsValueCheckResult.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ERROR_LOST_LABEL, ['permission']);
|
||||
@ -506,28 +483,28 @@ export class TagValueCheck {
|
||||
const MODEL_COUNTS: number = 2;
|
||||
const FILENAME_MODEL_COUNT: number = 1;
|
||||
if (splitArray.length === MODEL_COUNT) {
|
||||
if (
|
||||
// 同一文件
|
||||
useinsteadValueCheckResult.state =
|
||||
splitArray[0].indexOf(PunctuationMark.LEFT_BRACKET) === -1 &&
|
||||
splitArray[0].indexOf(PunctuationMark.RIGHT_BRACKET) === -1
|
||||
) {
|
||||
// 同一文件
|
||||
useinsteadValueCheckResult.state = TagValueCheck.checkModule(splitArray[0]);
|
||||
}
|
||||
splitArray[0].indexOf(PunctuationMark.RIGHT_BRACKET) === -1 &&
|
||||
TagValueCheck.checkModule(splitArray[0]);
|
||||
} else if (splitArray.length === MODEL_COUNTS) {
|
||||
// 不同文件
|
||||
const fileNameArray: string[] = splitArray[0].split('.');
|
||||
if (fileNameArray.length === FILENAME_MODEL_COUNT) {
|
||||
// arkui
|
||||
if (!/^[A-Za-z0-9_]+\b$/.test(fileNameArray[0]) || !TagValueCheck.checkModule(splitArray[1])) {
|
||||
useinsteadValueCheckResult.state = false;
|
||||
}
|
||||
useinsteadValueCheckResult.state =
|
||||
useinsteadValueCheckResult.state &&
|
||||
/^[A-Za-z0-9_]+\b$/.test(fileNameArray[0]) &&
|
||||
TagValueCheck.checkModule(splitArray[1]);
|
||||
} else {
|
||||
// 非arkui
|
||||
let checkFileName: boolean = true;
|
||||
for (let i = 0; i < fileNameArray.length; i++) {
|
||||
if (fileNameArray[0] !== 'ohos' || !/^[A-Za-z0-9_]+\b$/.test(fileNameArray[i])) {
|
||||
checkFileName = false;
|
||||
}
|
||||
checkFileName =
|
||||
checkFileName &&
|
||||
fileNameArray[0] === 'ohos' &&
|
||||
/^[A-Za-z0-9_]+\b$/.test(fileNameArray[i]);
|
||||
}
|
||||
if (
|
||||
!checkFileName ||
|
||||
|
@ -88,27 +88,28 @@ export class TsSyntaxCheck {
|
||||
if (fileSuffix === '.ts') {
|
||||
const targetSourceFile: ts.SourceFile = node.getSourceFile();
|
||||
programSourceFiles.forEach((programSourceFile) => {
|
||||
if (programSourceFile.fileName === targetSourceFile.fileName) {
|
||||
const result: readonly ts.Diagnostic[] = program.getSemanticDiagnostics(programSourceFile);
|
||||
result.forEach((item) => {
|
||||
const filePath: string = item.file?.fileName as string;
|
||||
const fileName: string = filePath.substring(filePath.indexOf('api'), filePath.length);
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.TS_SYNTAX_ERROR_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
fileName,
|
||||
ts.getLineAndCharacterOfPosition(node.getSourceFile(), item.start as number),
|
||||
ErrorType.TS_SYNTAX_ERROR,
|
||||
LogType.LOG_API,
|
||||
-1,
|
||||
'NA',
|
||||
'NA',
|
||||
item.messageText as string,
|
||||
tsResult,
|
||||
checkErrorAllInfos
|
||||
);
|
||||
});
|
||||
if (programSourceFile.fileName !== targetSourceFile.fileName) {
|
||||
return;
|
||||
}
|
||||
const result: readonly ts.Diagnostic[] = program.getSemanticDiagnostics(programSourceFile);
|
||||
result.forEach((item) => {
|
||||
const filePath: string = item.file?.fileName as string;
|
||||
const fileName: string = filePath.substring(filePath.indexOf('api'), filePath.length);
|
||||
AddErrorLogs.addAPICheckErrorLogs(
|
||||
ErrorID.TS_SYNTAX_ERROR_ID,
|
||||
ErrorLevel.MIDDLE,
|
||||
fileName,
|
||||
ts.getLineAndCharacterOfPosition(node.getSourceFile(), item.start as number),
|
||||
ErrorType.TS_SYNTAX_ERROR,
|
||||
LogType.LOG_API,
|
||||
-1,
|
||||
'NA',
|
||||
'NA',
|
||||
item.messageText as string,
|
||||
tsResult,
|
||||
checkErrorAllInfos
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
// ArkTS诊断日志
|
||||
|
@ -27,8 +27,8 @@ import { tagsArrayOfOrder, officialTagArr, CommonFunctions } from '../../../util
|
||||
import { AddErrorLogs } from './compile_info';
|
||||
import { compositiveResult, compositiveLocalResult, punctuationMarkSet } from '../../../utils/checkUtils';
|
||||
import { Set } from 'typescript';
|
||||
import {dictionariesArr} from '../config/dictionaries.json';
|
||||
import {dictionariesSupplementaryArr} from '../config/dictionaries_supplementary.json';
|
||||
import { dictionariesArr } from '../config/dictionaries.json';
|
||||
import { dictionariesSupplementaryArr } from '../config/dictionaries_supplementary.json';
|
||||
const dictionariesSet: Set<string> = new Set([
|
||||
...dictionariesArr,
|
||||
...dictionariesSupplementaryArr,
|
||||
@ -43,18 +43,19 @@ export class WordsCheck {
|
||||
*/
|
||||
static wordCheckResultsProcessing(baseInfos: BasicApiInfo[]): void {
|
||||
baseInfos.forEach((baseInfo) => {
|
||||
if (baseInfo.getApiType() !== ApiType.SOURCE_FILE) {
|
||||
let apiText: string = baseInfo.getJsDocText() + baseInfo.getDefinedText();
|
||||
if (baseInfo.getApiType() === ApiType.IMPORT) {
|
||||
const importText: Array<ExportImportValue> = (baseInfo as ImportInfo).getImportValues();
|
||||
const importValueArr: string[] = [];
|
||||
importText.forEach(importValue => {
|
||||
importValueArr.push(importValue.key);
|
||||
});
|
||||
apiText = importValueArr.join('|');
|
||||
}
|
||||
WordsCheck.wordsCheck(apiText, baseInfo);
|
||||
if (baseInfo.getApiType() === ApiType.SOURCE_FILE) {
|
||||
return;
|
||||
}
|
||||
let apiText: string = baseInfo.getJsDocText() + baseInfo.getDefinedText();
|
||||
if (baseInfo.getApiType() === ApiType.IMPORT) {
|
||||
const importText: Array<ExportImportValue> = (baseInfo as ImportInfo).getImportValues();
|
||||
const importValueArr: string[] = [];
|
||||
importText.forEach(importValue => {
|
||||
importValueArr.push(importValue.key);
|
||||
});
|
||||
apiText = importValueArr.join('|');
|
||||
}
|
||||
WordsCheck.wordsCheck(apiText, baseInfo);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ export class NodeProcessorHelper {
|
||||
return interfaceInfo;
|
||||
}
|
||||
|
||||
static processGenericity(typeParameter: ts.TypeParameterDeclaration) {
|
||||
static processGenericity(typeParameter: ts.TypeParameterDeclaration): GenericInfo {
|
||||
const genericInfo: GenericInfo = new GenericInfo();
|
||||
genericInfo.setIsGenericity(true);
|
||||
genericInfo.setGenericContent(typeParameter.getText());
|
||||
@ -616,7 +616,7 @@ export class NodeProcessorHelper {
|
||||
methodInfo.setReturnValueType(methodNode.type.kind);
|
||||
if (Boolean(process.env.NEED_DETECTION)) {
|
||||
NodeProcessorHelper.processFunctionTypeReference(methodNode.type, methodInfo, new ParamInfo(ApiType
|
||||
.PARAM), false)
|
||||
.PARAM), false);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < methodNode.parameters.length; i++) {
|
||||
@ -647,7 +647,9 @@ export class NodeProcessorHelper {
|
||||
return paramInfo;
|
||||
}
|
||||
let typeMapValue: string | undefined = undefined;
|
||||
NodeProcessorHelper.processFunctionTypeReference(param.type, methodInfo, paramInfo, true)
|
||||
if (Boolean(process.env.NEED_DETECTION)) {
|
||||
NodeProcessorHelper.processFunctionTypeReference(param.type, methodInfo, paramInfo, true);
|
||||
}
|
||||
if (ts.isLiteralTypeNode(param.type)) {
|
||||
typeMapValue = typeMap.get(param.type.literal.kind);
|
||||
}
|
||||
@ -669,11 +671,11 @@ export class NodeProcessorHelper {
|
||||
*/
|
||||
static processFunctionTypeReference(typeNode: ts.TypeNode, methodInfo: MethodInfo, paramInfo: ParamInfo, isParam: boolean = true): void {
|
||||
if (ts.isTypeLiteralNode(typeNode)) {
|
||||
NodeProcessorHelper.processFunctionTypeObject(typeNode, methodInfo, paramInfo, isParam)
|
||||
NodeProcessorHelper.processFunctionTypeObject(typeNode, methodInfo, paramInfo, isParam);
|
||||
} else if (ts.isUnionTypeNode(typeNode)) {
|
||||
typeNode.types.forEach((type: ts.TypeNode) => {
|
||||
NodeProcessorHelper.processFunctionTypeReference(type, methodInfo, paramInfo, isParam)
|
||||
})
|
||||
NodeProcessorHelper.processFunctionTypeReference(type, methodInfo, paramInfo, isParam);
|
||||
});
|
||||
}
|
||||
if (!ts.isTypeReferenceNode(typeNode)) {
|
||||
return;
|
||||
@ -686,17 +688,18 @@ export class NodeProcessorHelper {
|
||||
if (!declarations) {
|
||||
return;
|
||||
}
|
||||
const declaration: ts.Declaration = declarations[0]
|
||||
const jsDocInfos: Comment.JsDocInfo[] = JsDocProcessorHelper.processJsDocInfos(declaration, ApiType.TYPE_ALIAS, methodInfo.getKitInfoFromParent(methodInfo));
|
||||
const declaration: ts.Declaration = declarations[0];
|
||||
const jsDocInfos: Comment.JsDocInfo[] = JsDocProcessorHelper.processJsDocInfos(declaration, ApiType.TYPE_ALIAS,
|
||||
methodInfo.getKitInfoFromParent(methodInfo));
|
||||
if (jsDocInfos.length === 0) {
|
||||
return;
|
||||
}
|
||||
const jsDoc: Comment.JsDocInfo = jsDocInfos[jsDocInfos.length - 1];
|
||||
jsDoc.removeTags()
|
||||
jsDoc.removeTags();
|
||||
if (isParam) {
|
||||
paramInfo.addTypeLocations(jsDoc)
|
||||
paramInfo.addTypeLocations(jsDoc);
|
||||
} else {
|
||||
methodInfo.addTypeLocations(jsDoc)
|
||||
methodInfo.addTypeLocations(jsDoc);
|
||||
}
|
||||
} catch (error) {
|
||||
} finally {
|
||||
@ -713,20 +716,22 @@ export class NodeProcessorHelper {
|
||||
* true:类型为参数(入参)的数据
|
||||
* false:类型为返回值(出参)的数据
|
||||
*/
|
||||
static processFunctionTypeObject(typeObject: ts.TypeLiteralNode, methodInfo: MethodInfo, paramInfo: ParamInfo, isParam: boolean = true) {
|
||||
typeObject.members.forEach(((member: ts.TypeElement) => {
|
||||
const jsDocInfos: Comment.JsDocInfo[] = JsDocProcessorHelper.processJsDocInfos(member, ApiType.TYPE_ALIAS, methodInfo.getKitInfoFromParent(methodInfo));
|
||||
static processFunctionTypeObject(typeObject: ts.TypeLiteralNode, methodInfo: MethodInfo, paramInfo: ParamInfo,
|
||||
isParam: boolean = true): void {
|
||||
typeObject.members.forEach((member: ts.TypeElement) => {
|
||||
const jsDocInfos: Comment.JsDocInfo[] = JsDocProcessorHelper.processJsDocInfos(member, ApiType.TYPE_ALIAS,
|
||||
methodInfo.getKitInfoFromParent(methodInfo));
|
||||
if (jsDocInfos.length === 0) {
|
||||
return;
|
||||
}
|
||||
const jsDoc: Comment.JsDocInfo = jsDocInfos[jsDocInfos.length - 1];
|
||||
jsDoc.removeTags()
|
||||
jsDoc.removeTags();
|
||||
if (isParam) {
|
||||
paramInfo.addObjLocations(jsDoc)
|
||||
paramInfo.addObjLocations(jsDoc);
|
||||
} else {
|
||||
methodInfo.addObjLocations(jsDoc)
|
||||
methodInfo.addObjLocations(jsDoc);
|
||||
}
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -251,7 +251,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.PropertyInfo[] = [];
|
||||
const propertyInfo: PropertyInfo = apiInfo as PropertyInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = propertyInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.PropertyInfo = new ResultsInfo.PropertyInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -281,7 +281,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.ClassInterfaceInfo[] = [];
|
||||
const classInfo: ClassInfo = apiInfo as ClassInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = classInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.ClassInterfaceInfo = new ResultsInfo.ClassInterfaceInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -306,7 +306,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.ClassInterfaceInfo[] = [];
|
||||
const interfaceInfo: InterfaceInfo = apiInfo as InterfaceInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = interfaceInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.ClassInterfaceInfo = new ResultsInfo.ClassInterfaceInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -331,7 +331,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.NamespaceEnumInfo[] = [];
|
||||
const interfaceInfo: NamespaceInfo = apiInfo as NamespaceInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = interfaceInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.NamespaceEnumInfo = new ResultsInfo.NamespaceEnumInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -351,7 +351,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.MethodInfo[] = [];
|
||||
const methodInfo: MethodInfo = apiInfo as MethodInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = methodInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.MethodInfo = new ResultsInfo.MethodInfo(apiInfo.getApiType(), new Comment.JsDocInfo());
|
||||
newInfo.setName(apiInfo.getApiName());
|
||||
newInfo.setCallForm(methodInfo.getCallForm());
|
||||
@ -407,7 +407,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.ConstantInfo[] = [];
|
||||
const constantInfo: ConstantInfo = apiInfo as ConstantInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = constantInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.ConstantInfo = new ResultsInfo.ConstantInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -443,7 +443,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.DeclareConstInfo[] = [];
|
||||
const constantInfo: ConstantInfo = apiInfo as ConstantInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = constantInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.DeclareConstInfo = new ResultsInfo.DeclareConstInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -475,7 +475,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.NamespaceEnumInfo[] = [];
|
||||
const enumInfo: EnumInfo = apiInfo as EnumInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = enumInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.NamespaceEnumInfo = new ResultsInfo.NamespaceEnumInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -495,7 +495,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.EnumValueInfo[] = [];
|
||||
const enumValueInfo: EnumValueInfo = apiInfo as EnumValueInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = enumValueInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.EnumValueInfo = new ResultsInfo.EnumValueInfo(
|
||||
apiInfo.getApiType(),
|
||||
new Comment.JsDocInfo()
|
||||
@ -517,7 +517,7 @@ export class ResultsProcessHelper {
|
||||
const infos: ResultsInfo.BasicApiInfo[] = [];
|
||||
const typeAliasInfo: TypeAliasInfo = apiInfo as TypeAliasInfo;
|
||||
const jsDocInfos: Comment.JsDocInfo[] = typeAliasInfo.getJsDocInfos();
|
||||
if (jsDocInfos.length == 0) {
|
||||
if (jsDocInfos.length === 0) {
|
||||
const newInfo: ResultsInfo.BasicApiInfo = ResultsProcessHelper.processTypeAliasGetNewInfo(
|
||||
typeAliasInfo,
|
||||
new Comment.JsDocInfo()
|
||||
|
@ -46,15 +46,15 @@ export class Parser {
|
||||
parserParam.setRootNames(files);
|
||||
}
|
||||
const apiMap: FilesMap = new Map();
|
||||
let collectFiles: Array<string> = []
|
||||
if (collectFile == '') {
|
||||
let collectFiles: Array<string> = [];
|
||||
if (collectFile === '') {
|
||||
collectFiles = files;
|
||||
} else if (FileUtils.isDirectory(collectFile)) {
|
||||
collectFiles = FileUtils.readFilesInDir(collectFile, (name) => {
|
||||
return name.endsWith(StringConstant.DTS_EXTENSION) || name.endsWith(StringConstant.DETS_EXTENSION);
|
||||
});
|
||||
} else if (FileUtils.isFile(collectFile)) {
|
||||
collectFiles = [collectFile]
|
||||
collectFiles = [collectFile];
|
||||
}
|
||||
collectFiles.forEach((filePath: string) => {
|
||||
Parser.parseFile(fileDir, filePath, apiMap);
|
||||
@ -88,9 +88,9 @@ export class Parser {
|
||||
const fileArr: Array<string> = [filePath];
|
||||
sourceFile.statements.forEach((statement: ts.Statement) => {
|
||||
if (ts.isImportDeclaration(statement) && statement.moduleSpecifier.getText().startsWith('./', 1)) {
|
||||
fileArr.push(path.resolve(filePath, '..', statement.moduleSpecifier.getText().replace(/'|"/g, '')))
|
||||
fileArr.push(path.resolve(filePath, '..', statement.moduleSpecifier.getText().replace(/'|"/g, '')));
|
||||
}
|
||||
})
|
||||
});
|
||||
if (Boolean(process.env.NEED_DETECTION)) {
|
||||
parserParam.setProgram(fileArr);
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ export class ApiResultSimpleInfo {
|
||||
filePath: string = '';
|
||||
location: string = '';
|
||||
message: string = '';
|
||||
type:string='';
|
||||
apiText:string='';
|
||||
type: string = '';
|
||||
apiText: string = '';
|
||||
|
||||
setID(id: number): ApiResultSimpleInfo {
|
||||
this.id = id;
|
||||
|
@ -91,7 +91,7 @@ export class BasicApiInfo {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
removeNode() {
|
||||
removeNode(): void {
|
||||
this.node = undefined;
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ export class BasicApiInfo {
|
||||
return this.jsDocText;
|
||||
}
|
||||
|
||||
setIsJoinType(jsJoinType: boolean) {
|
||||
setIsJoinType(jsJoinType: boolean): void {
|
||||
this.isJoinType = jsJoinType;
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ export class MethodInfo extends ApiInfo {
|
||||
}
|
||||
|
||||
addTypeLocations(typeLocation: Comment.JsDocInfo): void {
|
||||
this.typeLocations.push(typeLocation)
|
||||
this.typeLocations.push(typeLocation);
|
||||
}
|
||||
|
||||
getTypeLocations(): Comment.JsDocInfo[] {
|
||||
@ -605,7 +605,7 @@ export class MethodInfo extends ApiInfo {
|
||||
}
|
||||
|
||||
addObjLocations(ObjLocation: Comment.JsDocInfo): void {
|
||||
this.objLocations.push(ObjLocation)
|
||||
this.objLocations.push(ObjLocation);
|
||||
}
|
||||
|
||||
getObjLocations(): Comment.JsDocInfo[] {
|
||||
@ -639,7 +639,7 @@ export class ParamInfo {
|
||||
return this.apiType;
|
||||
}
|
||||
|
||||
setApiName(apiName: string) {
|
||||
setApiName(apiName: string): void {
|
||||
this.apiName = apiName;
|
||||
}
|
||||
|
||||
@ -680,7 +680,7 @@ export class ParamInfo {
|
||||
}
|
||||
|
||||
addTypeLocations(typeLocation: Comment.JsDocInfo): void {
|
||||
this.typeLocations.push(typeLocation)
|
||||
this.typeLocations.push(typeLocation);
|
||||
}
|
||||
|
||||
getTypeLocations(): Comment.JsDocInfo[] {
|
||||
@ -688,7 +688,7 @@ export class ParamInfo {
|
||||
}
|
||||
|
||||
addObjLocations(ObjLocation: Comment.JsDocInfo): void {
|
||||
this.objLocations.push(ObjLocation)
|
||||
this.objLocations.push(ObjLocation);
|
||||
}
|
||||
|
||||
getObjLocations(): Comment.JsDocInfo[] {
|
||||
@ -700,18 +700,18 @@ export class GenericInfo {
|
||||
isGenericity: boolean = false;
|
||||
genericContent: string = '';
|
||||
|
||||
setIsGenericity(isGenericity: boolean) {
|
||||
setIsGenericity(isGenericity: boolean): void {
|
||||
this.isGenericity = isGenericity;
|
||||
}
|
||||
getIsGenericity() {
|
||||
getIsGenericity(): boolean {
|
||||
return this.isGenericity;
|
||||
}
|
||||
|
||||
setGenericContent(genericContent: string) {
|
||||
setGenericContent(genericContent: string): void {
|
||||
this.genericContent = genericContent;
|
||||
}
|
||||
|
||||
getGenericContent() {
|
||||
getGenericContent(): string {
|
||||
return this.genericContent;
|
||||
}
|
||||
}
|
||||
@ -752,7 +752,7 @@ export class ParserParam {
|
||||
return this.fileDir;
|
||||
}
|
||||
|
||||
setFileDir(fileDir: string) {
|
||||
setFileDir(fileDir: string): void {
|
||||
this.fileDir = fileDir;
|
||||
}
|
||||
|
||||
@ -760,7 +760,7 @@ export class ParserParam {
|
||||
return this.filePath;
|
||||
}
|
||||
|
||||
setFilePath(filePath: string) {
|
||||
setFilePath(filePath: string): void {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
@ -768,7 +768,7 @@ export class ParserParam {
|
||||
return this.sdkPath;
|
||||
}
|
||||
|
||||
setSdkPath(sdkPath: string) {
|
||||
setSdkPath(sdkPath: string): void {
|
||||
this.sdkPath = sdkPath;
|
||||
}
|
||||
|
||||
@ -776,7 +776,7 @@ export class ParserParam {
|
||||
return this.rootNames;
|
||||
}
|
||||
|
||||
setRootNames(rootNames: string[]) {
|
||||
setRootNames(rootNames: string[]): void {
|
||||
this.rootNames = rootNames;
|
||||
}
|
||||
|
||||
@ -784,14 +784,14 @@ export class ParserParam {
|
||||
return this.tsProgram;
|
||||
}
|
||||
|
||||
getETSOptions(componentLibs: Array<string>) {
|
||||
getETSOptions(componentLibs: Array<string>): any {
|
||||
const tsconfig = require('../../config/tsconfig.json');
|
||||
const etsConfig = tsconfig.compilerOptions.ets;
|
||||
etsConfig.libs = [...componentLibs];
|
||||
return etsConfig;
|
||||
}
|
||||
|
||||
setProgram(apiLibs: Array<string>) {
|
||||
setProgram(apiLibs: Array<string>): void {
|
||||
const compilerOption = {
|
||||
target: ts.ScriptTarget.ES2017,
|
||||
ets: this.getETSOptions([]),
|
||||
@ -802,7 +802,7 @@ export class ParserParam {
|
||||
this.tsProgram = ts.createProgram({
|
||||
rootNames: [...apiLibs, ...this.rootNames],
|
||||
options: compilerOption
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ export class ApiInfo extends BasicApiInfo {
|
||||
this.isCrossPlatForm = jsDocInfo.getIsCrossPlatForm();
|
||||
this.isSystemApi = jsDocInfo.getIsSystemApi();
|
||||
this.isStageModelOnly = jsDocInfo.getModelLimitation().toLowerCase() === StringConstant.STAGE_MODEL_ONLY;
|
||||
// jsDocInfo.getIsStageModelOnly();
|
||||
this.isFaModelOnly = jsDocInfo.getModelLimitation().toLowerCase() === StringConstant.FA_MODEL_ONLY;
|
||||
this.deprecatedVersion = jsDocInfo.getDeprecatedVersion();
|
||||
this.useinstead = jsDocInfo.getUseinstead();
|
||||
|
@ -22,10 +22,10 @@ export class EnumUtils {
|
||||
* @return { any[] }
|
||||
* @memberof EnumUtils
|
||||
*/
|
||||
static enum2arr(valueEnum: any[] | Record<string, any>) {
|
||||
static enum2arr(valueEnum: any[] | Record<string, any>): any[] {
|
||||
let values: any[] = Array.isArray(valueEnum) ? valueEnum : Object.values(valueEnum);
|
||||
// 如果 enum 值为 number 类型,ts 生成的 js 对象会同时包含枚举的名称,针对该情形需提出枚举名称
|
||||
const hasNum = values.some((v) => typeof v === 'number');
|
||||
const hasNum: boolean = values.some((v) => typeof v === 'number');
|
||||
if (hasNum) {
|
||||
values = values.filter((v) => typeof v === 'number');
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import ts, { LineAndCharacter } from 'typescript';
|
||||
import { ApiResultSimpleInfo, ApiResultInfo, ApiResultMessage } from '../typedef/checker/result_type';
|
||||
import { ApiInfo, ClassInfo, ParentClass } from '../typedef/parser/ApiInfoDefination';
|
||||
import { FileUtils } from './FileUtils';
|
||||
import { ApiCheckVersion } from '../coreImpl/checker/config/api_check_version.json'
|
||||
import { ApiCheckVersion } from '../coreImpl/checker/config/api_check_version.json';
|
||||
|
||||
|
||||
export class PosOfNode {
|
||||
@ -157,10 +157,8 @@ export class ObtainFullPath {
|
||||
const status: Stats = fs.statSync(filePath);
|
||||
if (status.isDirectory()) {
|
||||
ObtainFullPath.getFullFiles(filePath, utFiles);
|
||||
} else {
|
||||
if (/\.d\.ts/.test(filePath) || /\.d\.ets/.test(filePath) || /\.ts/.test(filePath)) {
|
||||
utFiles.push(filePath);
|
||||
}
|
||||
} else if (/\.d\.ts/.test(filePath) || /\.d\.ets/.test(filePath) || /\.ts/.test(filePath)) {
|
||||
utFiles.push(filePath);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -34,25 +34,25 @@ export class LogLevelUtil {
|
||||
export class LogUtil {
|
||||
static logLevel: LogLevel = process.env.NODE_ENV === 'development' ? LogLevel.DEBUG : LogLevel.ERR;
|
||||
|
||||
static e(tag: string, message?: any) {
|
||||
static e(tag: string, message?: any): void {
|
||||
if (LogUtil.logLevel <= LogLevel.ERR) {
|
||||
console.error(`${tag}: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
static w(tag: string, message?: any) {
|
||||
static w(tag: string, message?: any): void {
|
||||
if (LogUtil.logLevel <= LogLevel.WARN) {
|
||||
console.warn(`${tag}: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
static i(tag: string, message?: any) {
|
||||
static i(tag: string, message?: any): void {
|
||||
if (LogUtil.logLevel <= LogLevel.INFO) {
|
||||
console.info(`${tag}: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
static d(tag: string, message?: any) {
|
||||
static d(tag: string, message?: any): void {
|
||||
if (LogUtil.logLevel <= LogLevel.DEBUG) {
|
||||
console.debug(`${tag}: ${message}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user