diff --git a/ets2panda/linter/src/cli/CommandLineParser.ts b/ets2panda/linter/src/cli/CommandLineParser.ts index 9849eedf17ddf941595d7bb0021890af6a008f74..1f3ae2b5124c23ccf40ba482b5a7a71170e990dc 100644 --- a/ets2panda/linter/src/cli/CommandLineParser.ts +++ b/ets2panda/linter/src/cli/CommandLineParser.ts @@ -132,7 +132,7 @@ function formIdeInteractive(cmdOptions: CommandLineOptions, commanderOpts: Optio cmdOptions.linterOptions.checkTsAndJs = true; } if (commanderOpts.onlyArkts2SyntaxRules) { - cmdOptions.onlySyntax = true; + cmdOptions.linterOptions.onlySyntax = true; } } diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 5af05d0e31d4fb5c119c8b7e7abed8baa51458fb..31568f4c8bf10bae560987d4ae1592e94bdddf98 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 e1e433013c991aa8d5ee31af47b3f558ad34519e..b756543ab9dd3e53c2b5481c2c25c46d26468abf 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,38 @@ export abstract class BaseTypeScriptLinter { autofix: autofix, autofixTitle: isMsgNumValid && autofix !== undefined ? cookBookRefToFixTitle.get(cookBookMsgNum) : undefined }; + + if (this.options?.ideInteractive && this.isSkipedRecordProblems(badNodeInfo)) { + 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 isSkipedRecordProblems(badNodeInfo: ProblemInfo): boolean { + if (this.options.onlySyntax) { + if (onlyArkts2SyntaxRules.has(badNodeInfo.ruleTag)) { + return false; + } + } else { + if (this.options.arkts2 + && arkts2Rules.includes(badNodeInfo.ruleTag)) { + return false; + } + } + return true; + } } diff --git a/ets2panda/linter/src/lib/CommandLineOptions.ts b/ets2panda/linter/src/lib/CommandLineOptions.ts index 1bdde46faeaa7c3be16eb3717c3f666ed2658765..d793e6204454b4cf520c1948013e30db6f293c35 100644 --- a/ets2panda/linter/src/lib/CommandLineOptions.ts +++ b/ets2panda/linter/src/lib/CommandLineOptions.ts @@ -27,7 +27,6 @@ export interface CommandLineOptions { arktsWholeProjectPath?: string; skipLinter?: boolean; homecheck?: boolean; - onlySyntax?: boolean; followSdkSettings?: boolean; devecoPluginModeDeprecated?: boolean; disableStrictDiagnostics?: boolean; diff --git a/ets2panda/linter/src/lib/LinterOptions.ts b/ets2panda/linter/src/lib/LinterOptions.ts index 72613a4cd1648f8febcc6e49c1263e7d21883b29..11c2183d5cf0d96c5adc7b4362c71a7edf126bc2 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; }