From c08aa17ac3d1768aeff7f8dc3c7bc95339888ed0 Mon Sep 17 00:00:00 2001 From: Stephen Carter Date: Thu, 5 Dec 2024 15:24:55 -0500 Subject: [PATCH] Final polish --- src/commands/code-analyzer/config.ts | 2 -- src/lib/actions/ConfigAction.ts | 5 ++--- src/lib/models/ConfigModel.ts | 7 +++++-- test/lib/actions/ConfigAction.test.ts | 5 ----- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/commands/code-analyzer/config.ts b/src/commands/code-analyzer/config.ts index e5249cc88..e53bf4cd2 100644 --- a/src/commands/code-analyzer/config.ts +++ b/src/commands/code-analyzer/config.ts @@ -8,7 +8,6 @@ import {EnginePluginsFactoryImpl} from '../../lib/factories/EnginePluginsFactory import {BundleName, getMessage, getMessages} from '../../lib/messages'; import {LogEventDisplayer} from '../../lib/listeners/LogEventListener'; import {RuleSelectionProgressSpinner} from '../../lib/listeners/ProgressEventListener'; -import {AnnotatedConfigModel} from '../../lib/models/ConfigModel'; import {Displayable, UxDisplay} from '../../lib/Display'; export default class ConfigCommand extends SfCommand implements Displayable { @@ -67,7 +66,6 @@ export default class ConfigCommand extends SfCommand implements Displayabl pluginsFactory: new EnginePluginsFactoryImpl(), logEventListeners: [new LogEventDisplayer(uxDisplay)], progressEventListeners: [new RuleSelectionProgressSpinner(uxDisplay)], - modelGenerator: AnnotatedConfigModel, actionSummaryViewer: new ConfigActionSummaryViewer(uxDisplay), viewer: new ConfigStyledYamlViewer(uxDisplay) }; diff --git a/src/lib/actions/ConfigAction.ts b/src/lib/actions/ConfigAction.ts index 81ea17f6c..f52bf24f2 100644 --- a/src/lib/actions/ConfigAction.ts +++ b/src/lib/actions/ConfigAction.ts @@ -8,12 +8,11 @@ import {createWorkspace} from '../utils/WorkspaceUtil'; import {LogEventListener, LogEventLogger} from '../listeners/LogEventListener'; import {ProgressEventListener} from '../listeners/ProgressEventListener'; import {ConfigActionSummaryViewer} from '../viewers/ActionSummaryViewer'; -import {ConfigModel, ConfigModelConstructor} from '../models/ConfigModel'; +import {AnnotatedConfigModel, ConfigModel} from '../models/ConfigModel'; export type ConfigDependencies = { configFactory: CodeAnalyzerConfigFactory; pluginsFactory: EnginePluginsFactory; - modelGenerator: ConfigModelConstructor; logEventListeners: LogEventListener[]; progressEventListeners: ProgressEventListener[]; writer?: ConfigWriter; @@ -109,7 +108,7 @@ export class ConfigAction { // We need the Set of all Engines that returned rules for the user's selection on both the Default and User Cores. const relevantEngines: Set = new Set([...userRules.getEngineNames(), ...selectedDefaultRules.getEngineNames()]); - const configModel: ConfigModel = new this.dependencies.modelGenerator(userConfig, userCore, userRules, allDefaultRules, relevantEngines); + const configModel: ConfigModel = new AnnotatedConfigModel(userConfig, userCore, userRules, allDefaultRules, relevantEngines); const fileWritten: boolean = this.dependencies.writer ? await this.dependencies.writer.write(configModel) diff --git a/src/lib/models/ConfigModel.ts b/src/lib/models/ConfigModel.ts index 0893e3635..d36ff98e6 100644 --- a/src/lib/models/ConfigModel.ts +++ b/src/lib/models/ConfigModel.ts @@ -21,13 +21,16 @@ export interface ConfigModel { toFormattedOutput(format: OutputFormat): string; } -export type ConfigModelConstructor = new (config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) => ConfigModel; - export class AnnotatedConfigModel implements ConfigModel { private readonly config: CodeAnalyzerConfig; // TODO: It would be nice if we updated the CodeAnalyzer (in our core module) to just return its CodeAnalyzerConfig with a getter so we didn't need to pass it around private readonly codeAnalyzer: CodeAnalyzer; private readonly userRules: RuleSelection; private readonly allDefaultRules: RuleSelection; + + // Note that it is important that we calculate the relevant engines list based on (the user rule selection with no + // config) plus (user rule selection with user config) since we still want to show the "disable_engine" config value + // in the output if a user even if selects an engine that is currently disabled. But we don't want to the engine + // configs not associated with the user's rule selection, thus we can't use the engines from allDefaultRules. private readonly relevantEngines: Set; constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { diff --git a/test/lib/actions/ConfigAction.test.ts b/test/lib/actions/ConfigAction.test.ts index b173b8387..4381b03e2 100644 --- a/test/lib/actions/ConfigAction.test.ts +++ b/test/lib/actions/ConfigAction.test.ts @@ -8,7 +8,6 @@ import * as EngineApi from "@salesforce/code-analyzer-engine-api"; import {CodeAnalyzerConfigFactory} from "../../../src/lib/factories/CodeAnalyzerConfigFactory"; import {EnginePluginsFactory} from '../../../src/lib/factories/EnginePluginsFactory'; import {ConfigAction, ConfigDependencies, ConfigInput} from '../../../src/lib/actions/ConfigAction'; -import {AnnotatedConfigModel} from '../../../src/lib/models/ConfigModel'; import {ConfigStyledYamlViewer} from '../../../src/lib/viewers/ConfigViewer'; import {ConfigActionSummaryViewer} from '../../../src/lib/viewers/ActionSummaryViewer'; @@ -37,7 +36,6 @@ describe('ConfigAction tests', () => { progressEventListeners: [], viewer: new ConfigStyledYamlViewer(spyDisplay), configFactory: new DefaultStubCodeAnalyzerConfigFactory(), - modelGenerator: AnnotatedConfigModel, actionSummaryViewer: new ConfigActionSummaryViewer(spyDisplay), pluginsFactory: new StubEnginePluginFactory() }; @@ -164,7 +162,6 @@ describe('ConfigAction tests', () => { progressEventListeners: [], viewer: new ConfigStyledYamlViewer(spyDisplay), configFactory: stubConfigFactory, - modelGenerator: AnnotatedConfigModel, actionSummaryViewer: new ConfigActionSummaryViewer(spyDisplay), pluginsFactory: new StubEnginePluginFactory() }; @@ -397,7 +394,6 @@ describe('ConfigAction tests', () => { progressEventListeners: [], viewer: new ConfigStyledYamlViewer(spyDisplay), configFactory: new DefaultStubCodeAnalyzerConfigFactory(), - modelGenerator: AnnotatedConfigModel, actionSummaryViewer: new ConfigActionSummaryViewer(spyDisplay), pluginsFactory: new StubEnginePluginFactory() }; @@ -446,7 +442,6 @@ describe('ConfigAction tests', () => { progressEventListeners: [], viewer: new ConfigStyledYamlViewer(spyDisplay), configFactory: new DefaultStubCodeAnalyzerConfigFactory(), - modelGenerator: AnnotatedConfigModel, actionSummaryViewer: new ConfigActionSummaryViewer(spyDisplay), pluginsFactory: new StubEnginePluginFactory() }