From dac66fa5e52ea8306cbc6401171acaf96e63c01c Mon Sep 17 00:00:00 2001 From: HuSenlin Date: Fri, 11 Jul 2025 17:33:49 +0800 Subject: [PATCH] progress bar is valid only IDE mode Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLR5Z Signed-off-by: HuSenlin --- ets2panda/linter/src/lib/LinterInputInfo.ts | 28 ++++++++++++++ ets2panda/linter/src/lib/LinterRunner.ts | 41 +++++++++++++++------ 2 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 ets2panda/linter/src/lib/LinterInputInfo.ts diff --git a/ets2panda/linter/src/lib/LinterInputInfo.ts b/ets2panda/linter/src/lib/LinterInputInfo.ts new file mode 100644 index 0000000000..1cfe8f05ff --- /dev/null +++ b/ets2panda/linter/src/lib/LinterInputInfo.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type * as ts from 'typescript'; +import type { LinterOptions } from './LinterOptions'; +import type { MigrationInfo } from './progress/MigrationInfo'; +import type { CmdProgressInfo } from './progress/CmdProgressInfo'; + +export interface LinterInputInfo { + tsProgram: ts.Program; + srcFiles: ts.SourceFile[]; + options: LinterOptions; + tscStrictDiagnostics: Map; + migrationInfo?: MigrationInfo; + cmdProgressInfo: CmdProgressInfo; +} diff --git a/ets2panda/linter/src/lib/LinterRunner.ts b/ets2panda/linter/src/lib/LinterRunner.ts index 113f67fd1b..2c8eead572 100644 --- a/ets2panda/linter/src/lib/LinterRunner.ts +++ b/ets2panda/linter/src/lib/LinterRunner.ts @@ -53,6 +53,7 @@ import { LibraryTypeCallDiagnosticChecker } from './utils/functions/LibraryTypeC import { mergeArrayMaps } from './utils/functions/MergeArrayMaps'; import { clearPathHelperCache, pathContainsDirectory } from './utils/functions/PathHelper'; import { processSyncErr } from './utils/functions/ProcessWrite'; +import { LinterInputInfo } from './LinterInputInfo'; function prepareInputFilesList(cmdOptions: CommandLineOptions): string[] { let inputFiles = cmdOptions.inputFiles.map((x) => { @@ -141,12 +142,8 @@ function lintFiles( tscStrictDiagnostics: Map, migrationInfo?: MigrationInfo ): LintRunResult { - const projectStats: ProjectStatistics = new ProjectStatistics(); - const problemsInfos: Map = new Map(); - TypeScriptLinter.initGlobals(); InteropTypescriptLinter.initGlobals(); - let fileCount: number = 0; const cmdProgressBar = new FixedLineProgressBar(); const cmdProgressInfo: CmdProgressInfo = { cmdProgressBar: cmdProgressBar, @@ -155,8 +152,31 @@ function lintFiles( options: options }; - process.stderr.write('\n'); - preProcessCmdProgressBar(cmdProgressInfo); + if (options.ideInteractive) { + process.stderr.write('\n'); + preProcessCmdProgressBar(cmdProgressInfo); + } + const linterInputInfo: LinterInputInfo = { + tsProgram: tsProgram, + srcFiles: srcFiles, + options: options, + tscStrictDiagnostics: tscStrictDiagnostics, + migrationInfo: migrationInfo, + cmdProgressInfo: cmdProgressInfo + }; + + const lintResult = executeLinter(linterInputInfo); + if (options.ideInteractive) { + postProcessCmdProgressBar(cmdProgressInfo); + } + return lintResult; +} + +function executeLinter(linterInputInfo: LinterInputInfo): LintRunResult { + const { tsProgram, srcFiles, options, tscStrictDiagnostics, migrationInfo, cmdProgressInfo } = linterInputInfo; + const projectStats: ProjectStatistics = new ProjectStatistics(); + const problemsInfos: Map = new Map(); + let fileCount : number = 0; for (const srcFile of srcFiles) { const linter: BaseTypeScriptLinter = !options.interopCheckMode ? new TypeScriptLinter(tsProgram.getTypeChecker(), options, srcFile, tscStrictDiagnostics) : @@ -167,21 +187,18 @@ function lintFiles( problemsInfos.set(path.normalize(srcFile.fileName), [...problems]); projectStats.fileStats.push(linter.fileStats); fileCount += 1; - processCmdProgressBar(cmdProgressInfo, fileCount); if (options.ideInteractive) { + processCmdProgressBar(cmdProgressInfo, fileCount); processIdeProgressBar( { migrationInfo: migrationInfo, currentSrcFile: srcFile, srcFiles: srcFiles, options: options }, fileCount ); } } - - postProcessCmdProgressBar(cmdProgressInfo); - return { hasErrors: projectStats.hasError(), - problemsInfos, - projectStats + problemsInfos: problemsInfos, + projectStats: projectStats }; } -- Gitee