From 1cc834ddaa113559ea98d9abfc0e3e9cfc751d2c Mon Sep 17 00:00:00 2001 From: fanglou Date: Fri, 16 May 2025 21:44:36 +0800 Subject: [PATCH] Processb Signed-off-by: fanglou Change-Id: Ia68beca7d0e81810b64bfab93435bb37a282c1cd --- ets2panda/linter/src/cli/LinterCLI.ts | 22 ++-------- ets2panda/linter/src/lib/CookBookMsg.ts | 9 ++-- ets2panda/linter/src/lib/LinterRunner.ts | 8 ++++ ets2panda/linter/src/lib/TypeScriptLinter.ts | 43 +++++++++++-------- .../linter/src/lib/autofixes/Autofixer.ts | 2 +- .../src/lib/utils/consts/ArkuiConstants.ts | 8 +++- .../src/lib/utils/functions/ProcessWrite.ts | 15 +++++++ 7 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 ets2panda/linter/src/lib/utils/functions/ProcessWrite.ts diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index de148aea60..7a8c875e08 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -28,6 +28,7 @@ import { arkts2Rules } from '../lib/utils/consts/ArkTS2Rules'; import type { ProblemInfo as HomeCheckProblemInfo } from 'homecheck'; import { MigrationTool } from 'homecheck'; import { getHomeCheckConfigInfo } from '../lib/HomeCheck'; +import { processSyncOut, processSyncErr } from '../lib/utils/functions/ProcessWrite'; export function run(): void { const commandLineArgs = process.argv.slice(2); @@ -54,7 +55,6 @@ async function runIdeInteractiveMode(cmdOptions: CommandLineOptions): Promise(); if (cmdOptions.homecheck === true) { @@ -71,6 +71,8 @@ async function runIdeInteractiveMode(cmdOptions: CommandLineOptions): Promise { } } -async function processSyncOut(message: string): Promise { - await new Promise((resolve) => { - process.stdout.write(message, () => { - resolve('success'); - }); - }); -} - -async function processSyncErr(message: string): Promise { - await new Promise((resolve) => { - process.stderr.write(message, () => { - resolve('success'); - }); - }); -} - function getTempFileName(): string { return path.join(os.tmpdir(), Math.floor(Math.random() * 10000000).toString() + '_linter_tmp_file.ts'); } diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 0aeba63040..441bb95c85 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -327,12 +327,15 @@ cookBookTag[346] = 'Using "Symbol.iterator" is not allowed in this API (arkts-bu cookBookTag[347] = 'Not support propertydescriptor (arkts-builtin-no-property-descriptor)'; cookBookTag[348] = 'API is not support ctor signature and func (arkts-builtin-cotr)'; cookBookTag[349] = 'SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)'; -cookBookTag[350] = 'The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)'; -cookBookTag[351] = 'The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)'; +cookBookTag[350] = + 'The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)'; +cookBookTag[351] = + 'The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)'; cookBookTag[355] = 'Usage of standard library is restricted(arkts-limited-stdlib-no-sendable-decorator)'; cookBookTag[356] = 'Usage of standard library is restricted(arkts-limited-stdlib-no-concurrent-decorator)'; cookBookTag[357] = 'Worker are not supported(arkts-no-need-stdlib-worker)'; -cookBookTag[358] = 'Using "Object.getOwnPropertyNames" is not allowed in this API (arkts-builtin-object-getOwnPropertyNames))'; +cookBookTag[358] = + 'Using "Object.getOwnPropertyNames" is not allowed in this API (arkts-builtin-object-getOwnPropertyNames))'; cookBookTag[359] = '"@LocalBuilder" Decorator is not supported (arkui-no-localbuilder-decorator)'; for (let i = 0; i <= cookBookTag.length; i++) { cookBookMsg[i] = ''; diff --git a/ets2panda/linter/src/lib/LinterRunner.ts b/ets2panda/linter/src/lib/LinterRunner.ts index aac6ffe7bc..2def372cf6 100644 --- a/ets2panda/linter/src/lib/LinterRunner.ts +++ b/ets2panda/linter/src/lib/LinterRunner.ts @@ -40,6 +40,7 @@ import { compileLintOptions } from './ts-compiler/Compiler'; import * as qEd from './autofixes/QuasiEditor'; import { ProjectStatistics } from './statistics/ProjectStatistics'; import type { BaseTypeScriptLinter } from './BaseTypeScriptLinter'; +import { processSyncErr } from './utils/functions/ProcessWrite'; function prepareInputFilesList(cmdOptions: CommandLineOptions): string[] { let inputFiles = cmdOptions.inputFiles; @@ -121,6 +122,7 @@ function lintFiles( TypeScriptLinter.initGlobals(); InteropTypescriptLinter.initGlobals(); + let filesCounts: number = 0; for (const srcFile of srcFiles) { const linter: BaseTypeScriptLinter = !options.interopCheckMode ? @@ -130,6 +132,12 @@ function lintFiles( const problems = linter.problemsInfos; problemsInfos.set(path.normalize(srcFile.fileName), [...problems]); projectStats.fileStats.push(linter.fileStats); + filesCounts = filesCounts + 1; + if (options.ideInteractive) { + processSyncErr( + `{"content":"${srcFile.fileName}","messageType":1,"indicator":${filesCounts / srcFiles.length}}\n` + ); + } } return { diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index ebea94856c..fe2e969e56 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -3351,7 +3351,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdRecordType) || this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStringType) || !this.options.arkts2 && - (this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdMapType) || TsUtils.isIntrinsicObjectType(type)) || + (this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdMapType) || TsUtils.isIntrinsicObjectType(type)) || TsUtils.isEnumType(type) || // we allow EsObject here beacuse it is reported later using FaultId.EsObjectType TsUtils.isEsObjectType(typeNode) @@ -5260,7 +5260,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if ( this.compatibleSdkVersion > SENDBALE_FUNCTION_START_VERSION || this.compatibleSdkVersion === SENDBALE_FUNCTION_START_VERSION && - !SENDABLE_FUNCTION_UNSUPPORTED_STAGES_IN_API12.includes(this.compatibleSdkVersionStage) + !SENDABLE_FUNCTION_UNSUPPORTED_STAGES_IN_API12.includes(this.compatibleSdkVersionStage) ) { return true; } @@ -5692,9 +5692,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } if ( this.tsUtils.isOrDerivedFrom(lhsType, this.tsUtils.isArray) && - this.tsUtils.isOrDerivedFrom(rhsType, TsUtils.isTuple) || + this.tsUtils.isOrDerivedFrom(rhsType, TsUtils.isTuple) || this.tsUtils.isOrDerivedFrom(rhsType, this.tsUtils.isArray) && - this.tsUtils.isOrDerivedFrom(lhsType, TsUtils.isTuple) + this.tsUtils.isOrDerivedFrom(lhsType, TsUtils.isTuple) ) { this.incrementCounters(node, FaultID.NoTuplesArrays); } @@ -5970,7 +5970,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } else if (ts.isIdentifier(expr)) { this.fixJsImportExtendsClass(node.parent, expr); this.handleSdkDuplicateDeclName(expr); - } + } }); } } @@ -6759,7 +6759,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } - private processApiNodeSdkDuplicateDeclName (apiName: string, errorNode: ts.Node): void { + private processApiNodeSdkDuplicateDeclName(apiName: string, errorNode: ts.Node): void { const setApiListItem = TypeScriptLinter.globalApiInfo.get(SdkProblem.DeclWithDuplicateName); if (!setApiListItem) { return; @@ -6771,7 +6771,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!hasSameApiName) { return; } - + if (ts.isTypeReferenceNode(errorNode)) { errorNode = errorNode.typeName; } @@ -6786,13 +6786,15 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (matchedApi) { this.incrementCounters(errorNode, FaultID.DuplicateDeclNameFromSdk); } - }; + } - private handleSdkDuplicateDeclName(node: ts.TypeReferenceNode | ts.NewExpression | ts.ExpressionWithTypeArguments | ts.Identifier): void { + private handleSdkDuplicateDeclName( + node: ts.TypeReferenceNode | ts.NewExpression | ts.ExpressionWithTypeArguments | ts.Identifier + ): void { if (!this.options.arkts2) { return; } - + if (ts.isTypeReferenceNode(node)) { const typeName = node.typeName; if (ts.isIdentifier(typeName)) { @@ -6808,7 +6810,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (ts.isIdentifier(node)) { this.processApiNodeSdkDuplicateDeclName(node.text, node); - } + } } private getOriginalSymbol(node: ts.Node): ts.Symbol | undefined { @@ -7105,9 +7107,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - const faultId = propertyAccess.name.text === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST ? - FaultID.SetCloneListDeprecated : - FaultID.SetTransferListDeprecated; + const faultId = + propertyAccess.name.text === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST ? + FaultID.SetCloneListDeprecated : + FaultID.SetTransferListDeprecated; this.incrementCounters(node.parent, faultId); } @@ -7116,15 +7119,19 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } const methodName = propertyAccess.name.text; - return methodName === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST || - methodName === DEPRECATED_TASKPOOL_METHOD_SETTRANSFERLIST; + return ( + methodName === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST || + methodName === DEPRECATED_TASKPOOL_METHOD_SETTRANSFERLIST + ); } private static isTaskPoolTaskCreation(taskpoolExpr: ts.Expression): boolean { - return ts.isPropertyAccessExpression(taskpoolExpr) && + return ( + ts.isPropertyAccessExpression(taskpoolExpr) && ts.isIdentifier(taskpoolExpr.expression) && taskpoolExpr.expression.text === STDLIB_TASKPOOL_OBJECT_NAME && - taskpoolExpr.name.text === STDLIB_TASK_CLASS_NAME; + taskpoolExpr.name.text === STDLIB_TASK_CLASS_NAME + ); } private checkStdLibConcurrencyImport(importDeclaration: ts.ImportDeclaration): void { diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 8c253616b9..2057444391 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4182,7 +4182,7 @@ export class Autofixer { const replacement = this.printer.printNode(ts.EmitHint.Unspecified, propertyAccessExpr, node.getSourceFile()); return [{ start: node.getStart(), end: node.getEnd(), replacementText: replacement }]; } - + fixBuilderDecorators(decorator: ts.Decorator): Autofix[] | undefined { const newDecorator = ts.factory.createDecorator(ts.factory.createIdentifier('Builder')); const text = this.printer.printNode(ts.EmitHint.Unspecified, newDecorator, decorator.getSourceFile()); diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts index 722ee1ba34..b7b26501e9 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts @@ -46,7 +46,13 @@ export const observedDecoratorName: Set = new Set([ 'Track' ]); -export const skipImportDecoratorName: Set = new Set(['Extend', 'Styles', 'Sendable', 'Concurrent', 'LocalBuilder']); +export const skipImportDecoratorName: Set = new Set([ + 'Extend', + 'Styles', + 'Sendable', + 'Concurrent', + 'LocalBuilder' +]); export const ENTRY_DECORATOR_NAME = 'Entry'; export const ENTRY_STORAGE_PROPERITY = 'storage'; diff --git a/ets2panda/linter/src/lib/utils/functions/ProcessWrite.ts b/ets2panda/linter/src/lib/utils/functions/ProcessWrite.ts new file mode 100644 index 0000000000..347684bc3b --- /dev/null +++ b/ets2panda/linter/src/lib/utils/functions/ProcessWrite.ts @@ -0,0 +1,15 @@ +export async function processSyncOut(message: string): Promise { + await new Promise((resolve) => { + process.stdout.write(message, () => { + resolve('success'); + }); + }); +} + +export async function processSyncErr(message: string): Promise { + await new Promise((resolve) => { + process.stderr.write(message, () => { + resolve('success'); + }); + }); +} -- Gitee