From bd6ce51cff8aef90cbef46590d16a45bea4fd88b Mon Sep 17 00:00:00 2001 From: Stephen Carter <123964848+stephen-carter-at-sf@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:53:07 -0400 Subject: [PATCH] CHANGE: @W-16606152@: Normalize engine configs to better support the config command for the cli (#85) --- packages/code-analyzer-core/package.json | 2 +- .../code-analyzer-core/src/code-analyzer.ts | 17 +++++++++++------ packages/code-analyzer-core/src/messages.ts | 3 +++ .../code-analyzer-core/test/add-engines.test.ts | 2 +- packages/code-analyzer-core/test/stubs.ts | 4 +--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/code-analyzer-core/package.json b/packages/code-analyzer-core/package.json index 49e978d7..c4623944 100644 --- a/packages/code-analyzer-core/package.json +++ b/packages/code-analyzer-core/package.json @@ -1,7 +1,7 @@ { "name": "@salesforce/code-analyzer-core", "description": "Core Package for the Salesforce Code Analyzer", - "version": "0.13.0", + "version": "0.13.1", "author": "The Salesforce Code Analyzer Team", "license": "BSD-3-Clause", "homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview", diff --git a/packages/code-analyzer-core/src/code-analyzer.ts b/packages/code-analyzer-core/src/code-analyzer.ts index 976edb6b..8f3a099f 100644 --- a/packages/code-analyzer-core/src/code-analyzer.ts +++ b/packages/code-analyzer-core/src/code-analyzer.ts @@ -240,7 +240,7 @@ export class CodeAnalyzer { try { const engineConfigDescription: engApi.ConfigDescription = enginePluginV1.describeEngineConfig(engineName); - addDisableEngineFieldDescription(engineConfigDescription, engineName); + normalizeEngineConfigDescription(engineConfigDescription, engineName); this.engineConfigDescriptions.set(engineName, engineConfigDescription); } catch (err) { throw new Error(getMessage('PluginErrorWhenCreatingEngine', engineName, (err as Error).message)); @@ -524,10 +524,15 @@ function isIntegerBetween(value: number, leftBound: number, rightBound: number): return value >= leftBound && value <= rightBound && Number.isInteger(value); } -function addDisableEngineFieldDescription(engineConfigDescription: ConfigDescription, engineName: string): void { - if (!engineConfigDescription.fieldDescriptions) { - engineConfigDescription.fieldDescriptions = {}; +function normalizeEngineConfigDescription(engineConfigDescription: ConfigDescription, engineName: string): void { + // Every engine config should have an overview, so if missing, then we add in a generic one + if (!engineConfigDescription.overview) { + engineConfigDescription.overview = getMessage('GenericEngineConfigOverview', engineName.toUpperCase()); + } + + // Every engine config should have a disable_engine field which we prefer to be first in the object for display purposes + engineConfigDescription.fieldDescriptions = { + [FIELDS.DISABLE_ENGINE]: getMessage('EngineConfigFieldDescription_disable_engine', engineName), + ... engineConfigDescription.fieldDescriptions } - engineConfigDescription.fieldDescriptions[FIELDS.DISABLE_ENGINE] = - getMessage('EngineConfigFieldDescription_disable_engine', engineName); } \ No newline at end of file diff --git a/packages/code-analyzer-core/src/messages.ts b/packages/code-analyzer-core/src/messages.ts index b38a53bf..6f2b74fc 100644 --- a/packages/code-analyzer-core/src/messages.ts +++ b/packages/code-analyzer-core/src/messages.ts @@ -36,6 +36,9 @@ const MESSAGE_CATALOG : MessageCatalog = { ` {property_name} is the name of a property that you would like to override.\n` + `Each engine may have its own set of properties available to help customize that particular engine's behavior.`, + GenericEngineConfigOverview: + `%s ENGINE CONFIGURATION`, + EngineConfigFieldDescription_disable_engine: `Whether to turn off the '%s' engine so that it is not included when running Code Analyzer commands.`, diff --git a/packages/code-analyzer-core/test/add-engines.test.ts b/packages/code-analyzer-core/test/add-engines.test.ts index 4a7d3421..b6a4793f 100644 --- a/packages/code-analyzer-core/test/add-engines.test.ts +++ b/packages/code-analyzer-core/test/add-engines.test.ts @@ -176,7 +176,7 @@ describe("Tests for adding engines to Code Analyzer", () => { }); const engineConfigDescription2: ConfigDescription = codeAnalyzer.getEngineConfigDescription('stubEngine2'); expect(engineConfigDescription2).toEqual({ - overview: "OverviewForStub2", + overview: getMessage('GenericEngineConfigOverview', 'STUBENGINE2'), fieldDescriptions: { disable_engine: getMessage('EngineConfigFieldDescription_disable_engine', 'stubEngine2') } diff --git a/packages/code-analyzer-core/test/stubs.ts b/packages/code-analyzer-core/test/stubs.ts index 7ea22bab..ee1e1963 100644 --- a/packages/code-analyzer-core/test/stubs.ts +++ b/packages/code-analyzer-core/test/stubs.ts @@ -30,9 +30,7 @@ export class StubEnginePlugin extends engApi.EnginePluginV1 { } } } - return { - overview: 'OverviewForStub2' - } + return {} } async createEngineConfig(engineName: string, configValueExtractor: ConfigValueExtractor): Promise {