codeCheck问题修改

Signed-off-by: wangcaoyu <wangcaoyu@huawei.com>
This commit is contained in:
wangcaoyu 2024-07-10 09:14:28 +08:00
parent 2f36d147e6
commit 8994175cd2
20 changed files with 165 additions and 137 deletions

View File

@ -8,7 +8,7 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"testAll": "mocha --config test/mocha/.mocharc.jsonc", "testAll": "mocha --config test/mocha/.mocharc.jsonc",
"pack": "cross-env NODE_ENV='production' webpack --mode=production", "pack": "cross-env NODE_ENV='production' webpack --mode=production",
"build": "npm run pack --bundle --stats-error-details", "build": "npm run pack --bundle",
"product": "ts-node src/main.ts -i test/debug/ut_nest_007.d.ts -o test/debug/output.json" "product": "ts-node src/main.ts -i test/debug/ut_nest_007.d.ts -o test/debug/output.json"
}, },
"keywords": [], "keywords": [],

View File

@ -37,7 +37,7 @@ import { ApiStatisticsHelper } from '../coreImpl/statistics/Statistics';
import { ApiStatisticsInfo, StatisticsInfoValueType } from '../typedef/statistics/ApiStatistics'; import { ApiStatisticsInfo, StatisticsInfoValueType } from '../typedef/statistics/ApiStatistics';
import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor'; import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor';
import { ApiCountInfo } from '../typedef/count/ApiCount'; import { ApiCountInfo } from '../typedef/count/ApiCount';
import { ApiCountHelper } from '../coreImpl/count/count' import { ApiCountHelper } from '../coreImpl/count/count';
import { CommonFunctions } from '../utils/checkUtils'; import { CommonFunctions } from '../utils/checkUtils';
import { FunctionUtils, KitData } from '../utils/FunctionUtils'; import { FunctionUtils, KitData } from '../utils/FunctionUtils';
import { ApiType } from '../typedef/parser/ApiInfoDefination'; import { ApiType } from '../typedef/parser/ApiInfoDefination';
@ -374,7 +374,7 @@ function collectApiCallback(apiData: ApiStatisticsInfo[], workbook: ExcelJS.Work
* @param apiData * @param apiData
* @param workbook * @param workbook
*/ */
function handleCollectData(apiData: ApiStatisticsInfo[], workbook: ExcelJS.Workbook){ function handleCollectData(apiData: ApiStatisticsInfo[], workbook: ExcelJS.Workbook): void {
const sheet: ExcelJS.Worksheet = workbook.addWorksheet(); const sheet: ExcelJS.Worksheet = workbook.addWorksheet();
const apiRelationsSet: Set<string> = new Set(); const apiRelationsSet: Set<string> = new Set();
const kitData: KitData = FunctionUtils.readKitFile(); const kitData: KitData = FunctionUtils.readKitFile();
@ -579,8 +579,7 @@ function detectionApi(options: OptionObjType): ToolNameValueType {
'detection.json' 'detection.json'
)} -O ${path.resolve(options.output)}`; )} -O ${path.resolve(options.output)}`;
} else if (process.env.NODE_ENV === 'production') { } else if (process.env.NODE_ENV === 'production') {
runningCommand = `${path.resolve(FileUtils.getBaseDirName(), './main.exe')} -N detection -L ${ runningCommand = `${path.resolve(FileUtils.getBaseDirName(), './main.exe')} -N detection -L ${options.checkLabels
options.checkLabels
} -P ${path.resolve(path.dirname(options.output), 'detection.json')} -O ${path.resolve(options.output)}`; } -P ${path.resolve(path.dirname(options.output), 'detection.json')} -O ${path.resolve(options.output)}`;
} }
buffer = execSync(runningCommand, { buffer = execSync(runningCommand, {
@ -688,7 +687,7 @@ function diffApiCallback(
WriterHelper.MarkdownReporter.writeInMarkdown(data, dest); WriterHelper.MarkdownReporter.writeInMarkdown(data, dest);
if (options?.all) { if (options?.all) {
addApiNumberSheet(relationsSet, workbook, data, kitData) addApiNumberSheet(relationsSet, workbook, data, kitData);
} }
@ -702,7 +701,8 @@ function diffApiCallback(
* @param data * @param data
* @param kitData * @param kitData
*/ */
function addApiNumberSheet(relationsSet: Set<string>, workbook: ExcelJS.Workbook, data: BasicDiffInfo[], kitData: KitData){ function addApiNumberSheet(relationsSet: Set<string>, workbook: ExcelJS.Workbook, data: BasicDiffInfo[],
kitData: KitData): void {
const numberSheet: ExcelJS.Worksheet = workbook.addWorksheet('api变更数量统计'); const numberSheet: ExcelJS.Worksheet = workbook.addWorksheet('api变更数量统计');
numberSheet.views = [{ xSplit: 2 }]; numberSheet.views = [{ xSplit: 2 }];
numberSheet.getRow(1).values = [ numberSheet.getRow(1).values = [
@ -789,34 +789,23 @@ function handleData(data: BasicDiffInfo[], diffTypeNumberArr: DiffNumberInfo[]):
* @param diffNumberInfo * @param diffNumberInfo
* @returns * @returns
*/ */
function getCompatibleObject(diffNumberInfo: DiffNumberInfo) { function getCompatibleObject(diffNumberInfo: DiffNumberInfo): string {
const compatibleInfoSet: Set<boolean> = new Set(diffNumberInfo.getAllCompatible()); const compatibleInfoSet: Set<boolean> = new Set(diffNumberInfo.getAllCompatible());
let compatibleSign = 0; let compatibleSign = 0;
let incompatibleSign = 0; let incompatibleSign = 0;
if (compatibleInfoSet.size === 2) { if (compatibleInfoSet.size === 2) {
compatibleSign = 1; compatibleSign = 1;
incompatibleSign = 1; incompatibleSign = 1;
return `{ } else if (compatibleInfoSet.has(true)) {
"兼容性":${compatibleSign},
"非兼容性":${incompatibleSign}
}`;
}
if (compatibleInfoSet.has(true)) {
compatibleSign = 1; compatibleSign = 1;
return `{ } else if (compatibleInfoSet.has(false)) {
"兼容性":${compatibleSign},
"非兼容性":${incompatibleSign}
}`;
}
if (compatibleInfoSet.has(false)) {
incompatibleSign = 1; incompatibleSign = 1;
}
return `{ return `{
"兼容性":${compatibleSign}, "兼容性":${compatibleSign},
"非兼容性":${incompatibleSign} "非兼容性":${incompatibleSign}
}`; }`;
} }
}
/** /**
* *
@ -824,14 +813,14 @@ function getCompatibleObject(diffNumberInfo: DiffNumberInfo) {
* @param diffNumberInfo * @param diffNumberInfo
* @returns * @returns
*/ */
function calculateChangeNumber(diffNumberInfo: DiffNumberInfo) { function calculateChangeNumber(diffNumberInfo: DiffNumberInfo): string {
const changeTypeSet: Set<string> = new Set(diffNumberInfo.getAllChangeType()); const changeTypeSet: Set<string> = new Set(diffNumberInfo.getAllChangeType());
let newApiNumber: number = 0, let newApiNumber: number = 0;
apiDeleteNumber = 0, let apiDeleteNumber: number = 0;
apiDeprecatedNumber = 0, let apiDeprecatedNumber: number = 0;
apiChangeNumber = 0, let apiChangeNumber: number = 0;
apiConstrainedChange = 0, let apiConstrainedChange: number = 0;
apiPrototypeChange = 0; let apiPrototypeChange: number = 0;
if (changeTypeSet.has('API修改原型修改')) { if (changeTypeSet.has('API修改原型修改')) {
apiPrototypeChange++; apiPrototypeChange++;
} }

View File

@ -19,7 +19,7 @@ import fs from 'fs';
import { LogUtil } from '../utils/logUtil'; import { LogUtil } from '../utils/logUtil';
import { ToolNameExcelCallback, joinNewMessage, joinOldMessage, ToolReturnData } from './config'; import { ToolNameExcelCallback, joinNewMessage, joinOldMessage, ToolReturnData } from './config';
import { BasicDiffInfo, diffTypeMap } from '../typedef/diff/ApiInfoDiff'; import { BasicDiffInfo, diffTypeMap } from '../typedef/diff/ApiInfoDiff';
import { OptionObjType } from './config' import { OptionObjType } from './config';
import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor'; import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor';
export namespace WriterHelper { export namespace WriterHelper {

View File

@ -52,8 +52,10 @@ export class EventMethodChecker {
const onEventPublishVersionValue: string = onEvent.length > 0 ? onEvent[0].jsDocInfos[0].since : '-1'; const onEventPublishVersionValue: string = onEvent.length > 0 ? onEvent[0].jsDocInfos[0].since : '-1';
const offEvent: MethodInfo[] = eventMethod.offEvents.length > 0 ? eventMethod.offEvents : []; const offEvent: MethodInfo[] = eventMethod.offEvents.length > 0 ? eventMethod.offEvents : [];
const offEventPublishVersionValue: string = offEvent.length > 0 ? offEvent[0].jsDocInfos[0].since : '-1'; const offEventPublishVersionValue: string = offEvent.length > 0 ? offEvent[0].jsDocInfos[0].since : '-1';
const isLostOnEvent: boolean = eventMethod.onEvents.length === 0 && eventMethod.offEvents.length !== 0 && offEventPublishVersionValue === JSON.stringify(ApiCheckVersion); const isLostOnEvent: boolean = eventMethod.onEvents.length === 0 && eventMethod.offEvents.length !== 0 &&
const isLostOffEvent: boolean = eventMethod.onEvents.length !== 0 && eventMethod.offEvents.length === 0 && onEventPublishVersionValue === JSON.stringify(ApiCheckVersion); offEventPublishVersionValue === JSON.stringify(ApiCheckVersion);
const isLostOffEvent: boolean = eventMethod.onEvents.length !== 0 && eventMethod.offEvents.length === 0 &&
onEventPublishVersionValue === JSON.stringify(ApiCheckVersion);
// check on&off event pair // check on&off event pair
if (isLostOnEvent || isLostOffEvent) { if (isLostOnEvent || isLostOffEvent) {

View File

@ -55,7 +55,7 @@ export class TagInheritCheck {
const trueCheckResult: ErrorTagFormat = { const trueCheckResult: ErrorTagFormat = {
state: true, state: true,
errorInfo: '', errorInfo: '',
} };
if (parentApisJsdoc === undefined) { if (parentApisJsdoc === undefined) {
return true; return true;
} }

View File

@ -79,7 +79,7 @@ export class LegalityCheck {
return apiLegalityCheckResult; return apiLegalityCheckResult;
} }
const tagsTag: string[] = []; const tagsTag: string[] = [];
apiTags.forEach((apiTag: Comment.CommentTag) => { tagsTag.push(apiTag.tag) }); apiTags.forEach((apiTag: Comment.CommentTag) => { tagsTag.push(apiTag.tag); });
if (tagsTag.includes('deprecated')) { if (tagsTag.includes('deprecated')) {
return apiLegalityCheckResult; return apiLegalityCheckResult;
} }
@ -223,7 +223,7 @@ export class LegalityCheck {
// check repeat throws // check repeat throws
const orderedThrowsCode: string[] = apiThrowsCode.sort(); const orderedThrowsCode: string[] = apiThrowsCode.sort();
for (var i = 0; i < orderedThrowsCode.length; i++) { for (var i = 0; i < orderedThrowsCode.length; i++) {
if (orderedThrowsCode[i] == orderedThrowsCode[i + 1]) { if (orderedThrowsCode[i] === orderedThrowsCode[i + 1]) {
apiRepeatThrows.state = false; apiRepeatThrows.state = false;
apiRepeatThrows.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ERROR_REPEATLABEL, ['throws']); apiRepeatThrows.errorInfo = CommonFunctions.createErrorInfo(ErrorMessage.ERROR_REPEATLABEL, ['throws']);
} }

View File

@ -38,7 +38,7 @@ export class TagValueCheck {
return tagValueError; return tagValueError;
} }
const tagsTag: string[] = []; const tagsTag: string[] = [];
tagsName.forEach((tagName: Comment.CommentTag) => { tagsTag.push(tagName.tag) }); tagsName.forEach((tagName: Comment.CommentTag) => { tagsTag.push(tagName.tag); });
const isDeprecated: boolean = tagsTag.includes('deprecated'); const isDeprecated: boolean = tagsTag.includes('deprecated');
tagsName.forEach((tag) => { tagsName.forEach((tag) => {
let errorTagInfo: ErrorTagFormat = { let errorTagInfo: ErrorTagFormat = {
@ -182,7 +182,7 @@ export class TagValueCheck {
let returnsApiValue: string[] = []; let returnsApiValue: string[] = [];
const legalApiArr: string[] = [ApiType.METHOD, ApiType.TYPE_ALIAS]; const legalApiArr: string[] = [ApiType.METHOD, ApiType.TYPE_ALIAS];
if (!legalApiArr.includes(singleApi.getApiType())) { if (!legalApiArr.includes(singleApi.getApiType())) {
return returnsValueCheckResult return returnsValueCheckResult;
} }
const spacealCase: string[] = CommonFunctions.judgeSpecialCase((singleApi as MethodInfo).returnValueType); const spacealCase: string[] = CommonFunctions.judgeSpecialCase((singleApi as MethodInfo).returnValueType);
if (singleApi.getApiType() === ApiType.TYPE_ALIAS) { if (singleApi.getApiType() === ApiType.TYPE_ALIAS) {
@ -230,7 +230,7 @@ export class TagValueCheck {
const genericArr: GenericInfo[] = singleApi.getGenericInfo(); const genericArr: GenericInfo[] = singleApi.getGenericInfo();
if (genericArr.length > 0) { if (genericArr.length > 0) {
let genericInfo = genericArr.map((generic) => { let genericInfo = genericArr.map((generic) => {
return generic.getGenericContent() return generic.getGenericContent();
}).join(','); }).join(',');
apiValue = apiValue + '<' + genericInfo + '>'; apiValue = apiValue + '<' + genericInfo + '>';
} }

View File

@ -672,7 +672,9 @@ export namespace DiffProcessorHelper {
const newReturnType: string[] = newApiInfo.getReturnType()?.split('|'); const newReturnType: string[] = newApiInfo.getReturnType()?.split('|');
const olaMethodTypeStr = oldReturnType.toString().replace(/\r|\n|\s+|'|"/g, ''); const olaMethodTypeStr = oldReturnType.toString().replace(/\r|\n|\s+|'|"/g, '');
const newMethodTypeStr = newReturnType.toString().replace(/\r|\n|\s+|'|"/g, ''); const newMethodTypeStr = newReturnType.toString().replace(/\r|\n|\s+|'|"/g, '');
if (olaMethodTypeStr === newMethodTypeStr) return; if (olaMethodTypeStr === newMethodTypeStr) {
return undefined;
}
diffTypeInfo.setOldMessage(olaMethodTypeStr).setNewMessage(newMethodTypeStr); diffTypeInfo.setOldMessage(olaMethodTypeStr).setNewMessage(newMethodTypeStr);
if (checkParentContainChild(newReturnType, oldReturnType)) { if (checkParentContainChild(newReturnType, oldReturnType)) {
return diffTypeInfo.setDiffType(ApiDiffType.TYPE_ALIAS_FUNCTION_RETURN_TYPE_ADD); return diffTypeInfo.setDiffType(ApiDiffType.TYPE_ALIAS_FUNCTION_RETURN_TYPE_ADD);
@ -786,15 +788,17 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
// 1.新旧版本参数一个不存在即不符合,直接返回 // 1.新旧版本参数一个不存在即不符合,直接返回
if (!oldParamLen || !newParamLen) return; if (!oldParamLen || !newParamLen) {
return;
}
// 2. 判断新旧版本参数名称相同的参数的个数和新旧版本的参数是否相同,相同即为新增或者减少参数 // 2. 判断新旧版本参数名称相同的参数的个数和新旧版本的参数是否相同,相同即为新增或者减少参数
// 2.1 循环得到所有的参数名称 // 2.1 循环得到所有的参数名称
const oldParamNames: string[] = [], const oldParamNames: string[] = [];
newParamNames: string[] = []; const newParamNames: string[] = [];
for (let i: number = 0; i < Math.max(oldParamLen, newParamLen); i++) { for (let i: number = 0; i < Math.max(oldParamLen, newParamLen); i++) {
const newCur: ParamInfo = newMethodParams[i]; const newCur: ParamInfo = newMethodParams[i];
const oldCur: ParamInfo = oldMethodParams[i]; const oldCur: ParamInfo = oldMethodParams[i];
@ -808,7 +812,9 @@ export namespace DiffProcessorHelper {
// 2.3 得到参数相同的个数 // 2.3 得到参数相同的个数
const sameParamsLength: number = oldParamLen - oldDiffParams.length; const sameParamsLength: number = oldParamLen - oldDiffParams.length;
// 2.4 判断新旧版本参数名称相同的参数的个数和新旧版本的参数是否相同,相同即为新增或者减少参数 // 2.4 判断新旧版本参数名称相同的参数的个数和新旧版本的参数是否相同,相同即为新增或者减少参数
if (sameParamsLength === oldParamLen || sameParamsLength === newParamLen) return; if (sameParamsLength === oldParamLen || sameParamsLength === newParamLen) {
return;
}
let oldDiffInfos: ParamInfo[] = oldMethodParams; let oldDiffInfos: ParamInfo[] = oldMethodParams;
let newDiffInfos: ParamInfo[] = newMethodParams; let newDiffInfos: ParamInfo[] = newMethodParams;
@ -841,17 +847,23 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
// 1.如果旧版本的参数长度不大于1,或者两者长度不一致,直接返回 // 1.如果旧版本的参数长度不大于1,或者两者长度不一致,直接返回
if (oldParamLen <= 1 || oldParamLen !== newParamLen) return; if (oldParamLen <= 1 || oldParamLen !== newParamLen) {
return;
}
// 2.判断两个版本的相同位置的参数名称是否一致,相同直接返回 // 2.判断两个版本的相同位置的参数名称是否一致,相同直接返回
const isSamePosition: boolean = checkIsSameOfSamePosition(newMethodParams, oldMethodParams); const isSamePosition: boolean = checkIsSameOfSamePosition(newMethodParams, oldMethodParams);
if (isSamePosition) return; if (isSamePosition) {
return;
}
// 3.如果旧版本的参数不完全包含新版本的参数或者两个版本的参数是否完全一致,一个不符合直接返回 // 3.如果旧版本的参数不完全包含新版本的参数或者两个版本的参数是否完全一致,一个不符合直接返回
const isContain: boolean = checkIsContain(oldMethodParams, newMethodParams); const isContain: boolean = checkIsContain(oldMethodParams, newMethodParams);
if (!isContain) return; if (!isContain) {
return;
}
// 4.上述情况都不符合,处理返回信息 // 4.上述情况都不符合,处理返回信息
const oldNamesStr: string = stitchMethodParameters(oldMethodParams); const oldNamesStr: string = stitchMethodParameters(oldMethodParams);
const newNamesStr: string = stitchMethodParameters(newMethodParams); const newNamesStr: string = stitchMethodParameters(newMethodParams);
@ -872,14 +884,18 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
// 1.如果新版本参数为空或者旧版本参数长度大于或者等于新版本参数长度,直接返回 // 1.如果新版本参数为空或者旧版本参数长度大于或者等于新版本参数长度,直接返回
if (newParamLen === 0 || oldParamLen >= newParamLen) return; if (newParamLen === 0 || oldParamLen >= newParamLen) {
return;
}
// 2.新版本参数需要完全包含旧版本,如果不包含,直接返回 // 2.新版本参数需要完全包含旧版本,如果不包含,直接返回
const isContain: boolean = checkIsContain(newMethodParams, oldMethodParams); const isContain: boolean = checkIsContain(newMethodParams, oldMethodParams);
if (!isContain) return; if (!isContain) {
return;
}
// 3.是否存在新增的可选参数 // 3.是否存在新增的可选参数
const oldParamNames: string[] = oldMethodParams.map((oldParam: ParamInfo) => oldParam.getApiName()); const oldParamNames: string[] = oldMethodParams.map((oldParam: ParamInfo) => oldParam.getApiName());
const addParams: ParamInfo[] = newMethodParams.filter((newParam: ParamInfo) => { const addParams: ParamInfo[] = newMethodParams.filter((newParam: ParamInfo) => {
@ -887,7 +903,9 @@ export namespace DiffProcessorHelper {
return !oldParamNames.includes(curParamName) && !newParam.getIsRequired(); return !oldParamNames.includes(curParamName) && !newParam.getIsRequired();
}); });
// 4.新版本新增的参数是否存在参数是可选类型,不存在直接返回 // 4.新版本新增的参数是否存在参数是可选类型,不存在直接返回
if (!addParams.length) return; if (!addParams.length) {
return;
}
// 5.存在新增的参数是可选参数,处理返回信息 // 5.存在新增的参数是可选参数,处理返回信息
const addParamNamesStr: string = stitchMethodParameters(addParams); const addParamNamesStr: string = stitchMethodParameters(addParams);
const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo(); const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo();
@ -907,14 +925,18 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
// 1.如果新版本参数为空或者旧版本参数长度大于或者等于新版本参数长度,直接返回 // 1.如果新版本参数为空或者旧版本参数长度大于或者等于新版本参数长度,直接返回
if (newParamLen === 0 || oldParamLen >= newParamLen) return; if (newParamLen === 0 || oldParamLen >= newParamLen) {
return;
}
// 2.新版本参数需要完全包含旧版本,如果不包含,直接返回 // 2.新版本参数需要完全包含旧版本,如果不包含,直接返回
const isContain: boolean = checkIsContain(newMethodParams, oldMethodParams); const isContain: boolean = checkIsContain(newMethodParams, oldMethodParams);
if (!isContain) return; if (!isContain) {
return;
}
// 3.是否存在新增的必选参数 // 3.是否存在新增的必选参数
const oldParamNames: string[] = oldMethodParams.map((oldParam: ParamInfo) => oldParam.getApiName()); const oldParamNames: string[] = oldMethodParams.map((oldParam: ParamInfo) => oldParam.getApiName());
const addParams: ParamInfo[] = newMethodParams.filter((newParam: ParamInfo) => { const addParams: ParamInfo[] = newMethodParams.filter((newParam: ParamInfo) => {
@ -922,7 +944,9 @@ export namespace DiffProcessorHelper {
return !oldParamNames.includes(curParamName) && newParam.getIsRequired(); return !oldParamNames.includes(curParamName) && newParam.getIsRequired();
}); });
// 4.新版本新增的参数是否存在参数是必选类型,不存在直接返回 // 4.新版本新增的参数是否存在参数是必选类型,不存在直接返回
if (!addParams.length) return; if (!addParams.length) {
return;
}
// 5.存在新增的参数是可选参数,处理返回信息 // 5.存在新增的参数是可选参数,处理返回信息
const addParamNamesStr: string = stitchMethodParameters(addParams); const addParamNamesStr: string = stitchMethodParameters(addParams);
const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo(); const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo();
@ -942,14 +966,18 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
// 1.旧版本参数为空或者新版本参数长度大于或者等于旧版本参数长度,直接返回 // 1.旧版本参数为空或者新版本参数长度大于或者等于旧版本参数长度,直接返回
if (oldParamLen === 0 || newParamLen >= oldParamLen) return; if (oldParamLen === 0 || newParamLen >= oldParamLen) {
return;
}
// 2.如果旧版本的参数不包含新版本的参数,直接返回 // 2.如果旧版本的参数不包含新版本的参数,直接返回
const isContain: boolean = checkIsContain(oldMethodParams, newMethodParams); const isContain: boolean = checkIsContain(oldMethodParams, newMethodParams);
if (newParamLen > 0 && !isContain) return; if (newParamLen > 0 && !isContain) {
return;
}
// 3.参数减少,处理返回信息 // 3.参数减少,处理返回信息
const newParamNames: string[] = newMethodParams.map((newParam: ParamInfo) => newParam.getApiName()); const newParamNames: string[] = newMethodParams.map((newParam: ParamInfo) => newParam.getApiName());
const reduceParams: ParamInfo[] = oldMethodParams.filter( const reduceParams: ParamInfo[] = oldMethodParams.filter(
@ -972,17 +1000,21 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType diffMethodType: DiffMethodType
) { ): void {
// 1.新旧版本的参数长度应大于0 // 1.新旧版本的参数长度应大于0
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
if (!oldParamLen || !newParamLen) return; if (!oldParamLen || !newParamLen) {
return;
}
// 2.找到参数名称一致和参数类型一致的参数进行比较,不存在直接返回 // 2.找到参数名称一致和参数类型一致的参数进行比较,不存在直接返回
const sameParamInfos: ParamInfo[] = oldMethodParams.filter((oldParam: ParamInfo) => { const sameParamInfos: ParamInfo[] = oldMethodParams.filter((oldParam: ParamInfo) => {
const oldParamName: string = oldParam.getApiName(); const oldParamName: string = oldParam.getApiName();
return newMethodParams.find((newParam: ParamInfo) => newParam.getApiName() === oldParamName); return newMethodParams.find((newParam: ParamInfo) => newParam.getApiName() === oldParamName);
}); });
if (!sameParamInfos.length) return; if (!sameParamInfos.length) {
return;
}
// 3.比较参数名和类型一致是否发生了可选/必选的变化,参数类型不需要计较 // 3.比较参数名和类型一致是否发生了可选/必选的变化,参数类型不需要计较
sameParamInfos.forEach((sameInfo: ParamInfo, idx: number) => { sameParamInfos.forEach((sameInfo: ParamInfo, idx: number) => {
const curOldParamName: string = sameInfo.getApiName(); const curOldParamName: string = sameInfo.getApiName();
@ -1015,17 +1047,21 @@ export namespace DiffProcessorHelper {
newMethodParams: ParamInfo[], newMethodParams: ParamInfo[],
diffTypeInfos: DiffTypeInfo[], diffTypeInfos: DiffTypeInfo[],
diffMethodType: DiffMethodType & DiffTypeChangeType diffMethodType: DiffMethodType & DiffTypeChangeType
) { ): void {
//1.判断新旧版本参数长度大于0 //1.判断新旧版本参数长度大于0
const oldParamLen: number = oldMethodParams.length; const oldParamLen: number = oldMethodParams.length;
const newParamLen: number = newMethodParams.length; const newParamLen: number = newMethodParams.length;
if (!oldParamLen || !newParamLen) return; if (!oldParamLen || !newParamLen) {
return;
}
const newParamName: string[] = newMethodParams.map((newParam: ParamInfo) => newParam.getApiName()); const newParamName: string[] = newMethodParams.map((newParam: ParamInfo) => newParam.getApiName());
// 2.需要新旧版本存在参数名称一致的,不存在直接返回 // 2.需要新旧版本存在参数名称一致的,不存在直接返回
const sameParamInfo: ParamInfo[] = oldMethodParams.filter((oldParam: ParamInfo) => const sameParamInfo: ParamInfo[] = oldMethodParams.filter((oldParam: ParamInfo) =>
newParamName.includes(oldParam.getApiName()) newParamName.includes(oldParam.getApiName())
); );
if (!sameParamInfo.length) return; if (!sameParamInfo.length) {
return;
}
// 3.寻找参数名称相同的情况下的参数类型变化的 // 3.寻找参数名称相同的情况下的参数类型变化的
sameParamInfo.forEach((curSame: ParamInfo, idx: number) => { sameParamInfo.forEach((curSame: ParamInfo, idx: number) => {
const oldParamTypes: string[] = curSame.getType(); const oldParamTypes: string[] = curSame.getType();
@ -1353,9 +1389,13 @@ export namespace DiffProcessorHelper {
const olaTypeAliasTypeStr: string = olaTypeAliasType.toString(); const olaTypeAliasTypeStr: string = olaTypeAliasType.toString();
const newTypeAliasTypeStr: string = newTypeAliasType.toString(); const newTypeAliasTypeStr: string = newTypeAliasType.toString();
// 1.两者定义相同,没有变化 // 1.两者定义相同,没有变化
if (olaTypeAliasTypeStr === newTypeAliasTypeStr) return; if (olaTypeAliasTypeStr === newTypeAliasTypeStr) {
return undefined;
}
// 自定义函数类型 // 自定义函数类型
if (oldApiInfo.getTypeIsFunction()) return; if (oldApiInfo.getTypeIsFunction()) {
return undefined;
}
// 2.两者定义不同 // 2.两者定义不同
const diffMethodType: DiffTypeChangeType = { const diffMethodType: DiffTypeChangeType = {
PARAM_TYPE_CHANGE: ApiDiffType.TYPE_ALIAS_CHANGE, PARAM_TYPE_CHANGE: ApiDiffType.TYPE_ALIAS_CHANGE,
@ -1468,7 +1508,7 @@ export namespace DiffProcessorHelper {
if (StringUtils.hasSubstring(oldParamTypeStr, newParamTypeStr)) { if (StringUtils.hasSubstring(oldParamTypeStr, newParamTypeStr)) {
return diffTypes.PARAM_TYPE_REDUCE; return diffTypes.PARAM_TYPE_REDUCE;
} }
return diffTypes.PARAM_TYPE_CHANGE return diffTypes.PARAM_TYPE_CHANGE;
} }
} }

View File

@ -289,7 +289,7 @@ export class DiffHelper {
return isAllDeprecated; return isAllDeprecated;
} }
static handleDeprecatedVersion(apiInfos: ApiInfo[]) { static handleDeprecatedVersion(apiInfos: ApiInfo[]): void {
let isAllDeprecated: boolean = true; let isAllDeprecated: boolean = true;
apiInfos.forEach((apiInfo: ApiInfo) => { apiInfos.forEach((apiInfo: ApiInfo) => {
const deprecatedVersion = apiInfo.getLastJsDocInfo()?.getDeprecatedVersion(); const deprecatedVersion = apiInfo.getLastJsDocInfo()?.getDeprecatedVersion();
@ -302,7 +302,7 @@ export class DiffHelper {
} }
apiInfos.forEach((apiInfo: ApiInfo) => { apiInfos.forEach((apiInfo: ApiInfo) => {
apiInfo.getLastJsDocInfo()?.setDeprecatedVersion('-1'); apiInfo.getLastJsDocInfo()?.setDeprecatedVersion('-1');
}) });
} }

View File

@ -283,10 +283,10 @@ export class NodeProcessorHelper {
if (ts.isStructDeclaration(node)) { if (ts.isStructDeclaration(node)) {
return ts.visitNodes(node.members, (node) => { return ts.visitNodes(node.members, (node) => {
if (ts.isConstructorDeclaration(node)) { if (ts.isConstructorDeclaration(node)) {
return return undefined;
} }
return node return node;
}) });
} }
if (ts.isTypeAliasDeclaration(node) && ts.isTypeLiteralNode(node.type)) { if (ts.isTypeAliasDeclaration(node) && ts.isTypeLiteralNode(node.type)) {
return node.type.members; return node.type.members;
@ -738,11 +738,11 @@ export class NodeProcessorHelper {
const fileSymbolMap: Map<string, ts.Symbol> | undefined = const fileSymbolMap: Map<string, ts.Symbol> | undefined =
NodeProcessorHelper.symbolOfTypeReferenceMap.get(filePath); NodeProcessorHelper.symbolOfTypeReferenceMap.get(filePath);
if (!fileSymbolMap) { if (!fileSymbolMap) {
return; return undefined;
} }
const typeSymbol: ts.Symbol | undefined = fileSymbolMap.get(tsNode.getFullText().trim()) const typeSymbol: ts.Symbol | undefined = fileSymbolMap.get(tsNode.getFullText().trim());
if (!typeSymbol) { if (!typeSymbol) {
return; return undefined;
} }
return typeSymbol; return typeSymbol;
} }
@ -776,7 +776,7 @@ export class NodeProcessorHelper {
if (parameter.type) { if (parameter.type) {
NodeProcessorHelper.processFunctionTypeNode(parameter.type, methodInfo, paramInfo, isParam); NodeProcessorHelper.processFunctionTypeNode(parameter.type, methodInfo, paramInfo, isParam);
} }
}) });
NodeProcessorHelper.processFunctionTypeNode(typeNode.type, methodInfo, paramInfo, isParam); NodeProcessorHelper.processFunctionTypeNode(typeNode.type, methodInfo, paramInfo, isParam);
} }
if (!ts.isTypeReferenceNode(typeNode)) { if (!ts.isTypeReferenceNode(typeNode)) {
@ -804,7 +804,7 @@ export class NodeProcessorHelper {
const typeArguments: ts.NodeArray<ts.TypeNode> | undefined = typeNode.typeArguments; const typeArguments: ts.NodeArray<ts.TypeNode> | undefined = typeNode.typeArguments;
typeArguments?.forEach((typeArgument: ts.TypeNode) => { typeArguments?.forEach((typeArgument: ts.TypeNode) => {
NodeProcessorHelper.processFunctionTypeNode(typeArgument, methodInfo, paramInfo, isParam); NodeProcessorHelper.processFunctionTypeNode(typeArgument, methodInfo, paramInfo, isParam);
}) });
try { try {
const tsProgram: ts.Program = parserParam.getTsProgram(); const tsProgram: ts.Program = parserParam.getTsProgram();
const filePath: string = parserParam.getFilePath(); const filePath: string = parserParam.getFilePath();
@ -816,7 +816,7 @@ export class NodeProcessorHelper {
} }
NodeProcessorHelper.setSymbolOfTypeReferenceMap(filePath, tsNode, symbol); NodeProcessorHelper.setSymbolOfTypeReferenceMap(filePath, tsNode, symbol);
} }
}) });
tsProgram.emit(); tsProgram.emit();
const currentTypeSymbol: ts.Symbol | undefined = const currentTypeSymbol: ts.Symbol | undefined =
NodeProcessorHelper.getSymbolOfTypeReferenceMap(filePath, typeNode); NodeProcessorHelper.getSymbolOfTypeReferenceMap(filePath, typeNode);

View File

@ -371,7 +371,6 @@ export class DiffNumberInfo {
apiRelation: string = ''; apiRelation: string = '';
isSystemapi: boolean = false; isSystemapi: boolean = false;
setApiName(apiName: string): DiffNumberInfo { setApiName(apiName: string): DiffNumberInfo {
this.apiName = apiName; this.apiName = apiName;
return this; return this;
@ -449,7 +448,7 @@ export class DiffNumberInfo {
setAllChangeType(changeType: string | undefined): DiffNumberInfo { setAllChangeType(changeType: string | undefined): DiffNumberInfo {
if (!changeType) { if (!changeType) {
return this return this;
} }
this.allChangeType.push(changeType); this.allChangeType.push(changeType);
return this; return this;
@ -476,7 +475,7 @@ export class DiffNumberInfo {
return this.diffTypeNumber; return this.diffTypeNumber;
} }
setIsApi(isApi: boolean) { setIsApi(isApi: boolean): DiffNumberInfo {
this.isApi = isApi; this.isApi = isApi;
return this; return this;
} }
@ -485,7 +484,7 @@ export class DiffNumberInfo {
return this.isApi; return this.isApi;
} }
setApiRelation(apiRelation: string) { setApiRelation(apiRelation: string): DiffNumberInfo {
this.apiRelation = apiRelation; this.apiRelation = apiRelation;
return this; return this;
} }
@ -505,7 +504,8 @@ export class DiffNumberInfo {
} }
export interface JsDocDiffProcessor { export interface JsDocDiffProcessor {
(oldJsDocInfo: Comment.JsDocInfo | undefined, newJsDocInfo: Comment.JsDocInfo | undefined, isAllDeprecated?: boolean, isAllSheet?: boolean): DiffTypeInfo | undefined; (oldJsDocInfo: Comment.JsDocInfo | undefined, newJsDocInfo: Comment.JsDocInfo | undefined, isAllDeprecated?: boolean,
isAllSheet?: boolean): DiffTypeInfo | undefined;
} }
export interface ApiSceneDiffProcessor { export interface ApiSceneDiffProcessor {
@ -962,4 +962,4 @@ export const isNotApiSet: Set<string> = new Set([
ApiType.NAMESPACE, ApiType.NAMESPACE,
ApiType.ENUM, ApiType.ENUM,
ApiType.SOURCE_FILE, ApiType.SOURCE_FILE,
]) ]);

View File

@ -72,10 +72,10 @@ export class BasicApiInfo {
constructor(apiType: string = '', node: ts.Node, parentApi: BasicApiInfo | undefined) { constructor(apiType: string = '', node: ts.Node, parentApi: BasicApiInfo | undefined) {
this.node = node; this.node = node;
this.setParentApi(parentApi); this.setParentApi(parentApi);
this.setParentApiType(parentApi?.getApiType()) this.setParentApiType(parentApi?.getApiType());
if (parentApi) { if (parentApi) {
this.setFilePath(parentApi.getFilePath()); this.setFilePath(parentApi.getFilePath());
this.setFileAbsolutePath(parentApi.getFileAbsolutePath()) this.setFileAbsolutePath(parentApi.getFileAbsolutePath());
this.setIsStruct(parentApi.getIsStruct()); this.setIsStruct(parentApi.getIsStruct());
} }
this.setApiType(apiType); this.setApiType(apiType);
@ -942,8 +942,8 @@ export class ParserParam {
const value: ts.ResolvedModule = { const value: ts.ResolvedModule = {
resolvedFileName: '', resolvedFileName: '',
isExternalLibraryImport: false isExternalLibraryImport: false
} };
const alias: { [key: string]: string } = { const alias: { [key: string]: string; } = {
"^(@ohos\\.inner\\.)(.*)$": "../../../base/ets/api/", "^(@ohos\\.inner\\.)(.*)$": "../../../base/ets/api/",
"^(@ohos\\.)(.*)$": "../../../base/ets/api/", "^(@ohos\\.)(.*)$": "../../../base/ets/api/",
}; };
@ -968,7 +968,7 @@ export class ParserParam {
break; break;
} }
} }
const resolvedFileName: string | undefined = ts.resolveModuleName(moduleName, containingFile, compilerOptions, compilerHost).resolvedModule?.resolvedFileName const resolvedFileName: string | undefined = ts.resolveModuleName(moduleName, containingFile, compilerOptions, compilerHost).resolvedModule?.resolvedFileName;
if (resolvedFileName) { if (resolvedFileName) {
value.resolvedFileName = resolvedFileName; value.resolvedFileName = resolvedFileName;
value.isExternalLibraryImport = true; value.isExternalLibraryImport = true;
@ -986,7 +986,7 @@ export class ParserParam {
} }
} }
export type ExportImportValue = { key: string; value: string }; export type ExportImportValue = { key: string; value: string; };
export interface NodeProcessorInterface { export interface NodeProcessorInterface {
(node: ts.Node, parentApiInfo: BasicApiInfo): BasicApiInfo; (node: ts.Node, parentApiInfo: BasicApiInfo): BasicApiInfo;
} }

View File

@ -20,8 +20,6 @@ export class StringUtils {
try { try {
flag = str.search(sub) !== -1; flag = str.search(sub) !== -1;
} catch (error) { } catch (error) {
console.log('str=',str)
console.log('sub=',sub)
LogUtil.e('StringUtils.hasSubstring', error); LogUtil.e('StringUtils.hasSubstring', error);
} }
return flag; return flag;

View File

@ -102,7 +102,6 @@ export class GenerateFile {
); );
} }
/** /**
* excel文件 * excel文件
* @param { ApiResultInfo[] } apiCheckArr * @param { ApiResultInfo[] } apiCheckArr
@ -262,7 +261,7 @@ export class CommonFunctions {
static getErrorInfo(singleApi: BasicApiInfo | undefined, apiJsdoc: Comment.JsDocInfo | undefined, filePath: string, errorBaseInfo: ErrorBaseInfo): ApiCheckInfo { static getErrorInfo(singleApi: BasicApiInfo | undefined, apiJsdoc: Comment.JsDocInfo | undefined, filePath: string, errorBaseInfo: ErrorBaseInfo): ApiCheckInfo {
let apiInfo: ApiCheckInfo = new ApiCheckInfo(); let apiInfo: ApiCheckInfo = new ApiCheckInfo();
if (singleApi === undefined) { if (singleApi === undefined) {
return apiInfo return apiInfo;
} }
const sinceVersion: number = apiJsdoc === undefined ? -1 : toNumber(apiJsdoc.since); const sinceVersion: number = apiJsdoc === undefined ? -1 : toNumber(apiJsdoc.since);
apiInfo apiInfo