From 8a71651ac55b087f3330fba13b23fa461d7bf512 Mon Sep 17 00:00:00 2001 From: ohhusenlin Date: Thu, 19 Jun 2025 11:38:06 +0800 Subject: [PATCH] fix issue for the conflict 1.1 and 1.2 rule Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGCI9 Signed-off-by: ohhusenlin --- ets2panda/linter/src/cli/LinterCLI.ts | 11 ------- .../linter/src/lib/BaseTypeScriptLinter.ts | 33 +++++++++++++++++-- ets2panda/linter/src/lib/LinterOptions.ts | 1 + ets2panda/linter/src/lib/utils/TsUtils.ts | 4 +++ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 5af05d0e31..31568f4c8b 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -24,7 +24,6 @@ import type { ProblemInfo } from '../lib/ProblemInfo'; import { parseCommandLine } from './CommandLineParser'; import { compileLintOptions, getEtsLoaderPath } from '../lib/ts-compiler/Compiler'; import { logStatistics } from '../lib/statistics/StatisticsLogger'; -import { arkts2Rules, onlyArkts2SyntaxRules } from '../lib/utils/consts/ArkTS2Rules'; import { MigrationTool } from 'homecheck'; import { getHomeCheckConfigInfo, transferIssues2ProblemInfo } from '../lib/HomeCheck'; @@ -100,16 +99,6 @@ function mergeLintProblems( mergedProblems.set(filePath, []); } let filteredProblems = problems; - if (cmdOptions.linterOptions.arkts2) { - filteredProblems = problems.filter((problem) => { - return arkts2Rules.includes(problem.ruleTag); - }); - } - if (cmdOptions.onlySyntax) { - filteredProblems = problems.filter((problem) => { - return onlyArkts2SyntaxRules.has(problem.ruleTag); - }); - } mergedProblems.get(filePath)!.push(...filteredProblems); if (cmdOptions.scanWholeProjectInHomecheck) { diff --git a/ets2panda/linter/src/lib/BaseTypeScriptLinter.ts b/ets2panda/linter/src/lib/BaseTypeScriptLinter.ts index e1e433013c..a250556a5f 100644 --- a/ets2panda/linter/src/lib/BaseTypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/BaseTypeScriptLinter.ts @@ -26,6 +26,7 @@ import { faultsAttrs } from './FaultAttrs'; import { cookBookTag } from './CookBookMsg'; import { FaultID } from './Problems'; import { ProblemSeverity } from './ProblemSeverity'; +import { arkts2Rules, onlyArkts2SyntaxRules } from './utils/consts/ArkTS2Rules'; export abstract class BaseTypeScriptLinter { problemsInfos: ProblemInfo[] = []; @@ -86,7 +87,7 @@ export abstract class BaseTypeScriptLinter { const cookBookTg = errorMsg ? errorMsg : cookBookTag[cookBookMsgNum]; const severity = faultsAttrs[faultId]?.severity ?? ProblemSeverity.ERROR; const isMsgNumValid = cookBookMsgNum > 0; - autofix = autofix ? BaseTypeScriptLinter.addLineColumnInfoInAutofix(autofix, startPos, endPos) : autofix; + autofix = BaseTypeScriptLinter.processAutofix(autofix, startPos, endPos); const badNodeInfo: ProblemInfo = { line: startPos.line + 1, column: startPos.character + 1, @@ -106,12 +107,40 @@ export abstract class BaseTypeScriptLinter { autofix: autofix, autofixTitle: isMsgNumValid && autofix !== undefined ? cookBookRefToFixTitle.get(cookBookMsgNum) : undefined }; + const linterOptions = this.tsUtils.getLinterOptions(); + if (linterOptions?.ideInteractive && BaseTypeScriptLinter.isSkipedReCordProblems(badNodeInfo, linterOptions)) { + return; + } + this.problemsInfos.push(badNodeInfo); this.updateFileStats(faultId, badNodeInfo.line); - // problems with autofixes might be collected separately if (this.options.reportAutofixCb && badNodeInfo.autofix) { this.options.reportAutofixCb(badNodeInfo); } } + + private static processAutofix( + autofix: Autofix[] | undefined, + startPos: ts.LineAndCharacter, + endPos: ts.LineAndCharacter + ): Autofix[] | undefined { + return autofix ? BaseTypeScriptLinter.addLineColumnInfoInAutofix(autofix, startPos, endPos) : autofix; + } + + private static isSkipedReCordProblems(badNodeInfo: ProblemInfo, linterOptions: LinterOptions): boolean { + let isArkts2Rules: boolean = false; + let isOnlyArkts2SyntaxRules: boolean = false; + if (linterOptions.arkts2) { + if (arkts2Rules.includes(badNodeInfo.ruleTag)) { + isArkts2Rules = true; + } + } + if (linterOptions?.ideInteractive && linterOptions.onlySyntax) { + if (onlyArkts2SyntaxRules.has(badNodeInfo.ruleTag)) { + isOnlyArkts2SyntaxRules = true; + } + } + return !(isArkts2Rules || isOnlyArkts2SyntaxRules); + } } diff --git a/ets2panda/linter/src/lib/LinterOptions.ts b/ets2panda/linter/src/lib/LinterOptions.ts index 72613a4cd1..11c2183d5c 100644 --- a/ets2panda/linter/src/lib/LinterOptions.ts +++ b/ets2panda/linter/src/lib/LinterOptions.ts @@ -46,4 +46,5 @@ export interface LinterOptions { wholeProjectPath?: string; checkTsAndJs?: boolean; inputFiles?: string[]; + onlySyntax?: boolean; } diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 7aa8050e88..1005dc9663 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -59,6 +59,10 @@ export class TsUtils { private readonly options: LinterOptions ) {} + getLinterOptions(): LinterOptions { + return this.options; + } + entityNameToString(name: ts.EntityName): string { if (ts.isIdentifier(name)) { return name.escapedText.toString(); -- Gitee