From d6369bb6e9019e944272ed2c53b127b939b95c91 Mon Sep 17 00:00:00 2001 From: ohhusenlin Date: Sat, 14 Jun 2025 22:05:04 +0800 Subject: [PATCH] Add progress bar when scanning and auto-fix Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICF7WQ Signed-off-by: ohhusenlin --- ets2panda/linter/src/cli/LinterCLI.ts | 17 +---------- ets2panda/linter/src/lib/LinterRunner.ts | 6 ++++ .../src/lib/utils/functions/ProcessWrite.ts | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 16 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 e45d56a7d5..cfcb8b5f70 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -27,6 +27,7 @@ import { logStatistics } from '../lib/statistics/StatisticsLogger'; import { arkts2Rules, onlyArkts2SyntaxRules } from '../lib/utils/consts/ArkTS2Rules'; import { MigrationTool } from 'homecheck'; import { getHomeCheckConfigInfo, transferIssues2ProblemInfo } from '../lib/HomeCheck'; +import { processSyncErr, processSyncOut } from '../lib/utils/functions/ProcessWrite'; export function run(): void { const commandLineArgs = process.argv.slice(2); @@ -131,22 +132,6 @@ async function generateReportFile(reportData, reportPath?: 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/LinterRunner.ts b/ets2panda/linter/src/lib/LinterRunner.ts index 453731f7bc..e673595da5 100644 --- a/ets2panda/linter/src/lib/LinterRunner.ts +++ b/ets2panda/linter/src/lib/LinterRunner.ts @@ -41,6 +41,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 '../lib/utils/functions/ProcessWrite'; function prepareInputFilesList(cmdOptions: CommandLineOptions): string[] { let inputFiles = cmdOptions.inputFiles.map((x) => { @@ -129,6 +130,7 @@ function lintFiles( TypeScriptLinter.initGlobals(); InteropTypescriptLinter.initGlobals(); + let fileCount: number = 0; for (const srcFile of srcFiles) { const linter: BaseTypeScriptLinter = !options.interopCheckMode ? @@ -138,6 +140,10 @@ function lintFiles( const problems = linter.problemsInfos; problemsInfos.set(path.normalize(srcFile.fileName), [...problems]); projectStats.fileStats.push(linter.fileStats); + fileCount = fileCount + 1; + if (options.ideInteractive) { + processSyncErr(`{"content":"${srcFile.fileName}","messageType":1,"indicator":${fileCount / srcFiles.length}}\n`); + } } return { 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..bb379f6f83 --- /dev/null +++ b/ets2panda/linter/src/lib/utils/functions/ProcessWrite.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022-2024 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. + */ + +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'); + }); + }); +} \ No newline at end of file -- Gitee