Skip to content

Commit

Permalink
CHANGE: @W-16606152@: Normalize engine configs to better support the …
Browse files Browse the repository at this point in the history
…config command for the cli (#85)
  • Loading branch information
stephen-carter-at-sf authored Sep 5, 2024
1 parent 5b1ecfa commit bd6ce51
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/code-analyzer-core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 11 additions & 6 deletions packages/code-analyzer-core/src/code-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions packages/code-analyzer-core/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,

Expand Down
2 changes: 1 addition & 1 deletion packages/code-analyzer-core/test/add-engines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
4 changes: 1 addition & 3 deletions packages/code-analyzer-core/test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export class StubEnginePlugin extends engApi.EnginePluginV1 {
}
}
}
return {
overview: 'OverviewForStub2'
}
return {}
}

async createEngineConfig(engineName: string, configValueExtractor: ConfigValueExtractor): Promise<ConfigObject> {
Expand Down

0 comments on commit bd6ce51

Please sign in to comment.