Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/code-analyzer-eslint-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/code-analyzer-eslint-engine",
"description": "Plugin package that adds 'eslint' as an engine into Salesforce Code Analyzer",
"version": "0.27.0",
"version": "0.28.0-SNAPSHOT",
"author": "The Salesforce Code Analyzer Team",
"license": "BSD-3-Clause",
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
Expand Down Expand Up @@ -76,4 +76,4 @@
"!src/index.ts"
]
}
}
}
4 changes: 4 additions & 0 deletions packages/code-analyzer-eslint-engine/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class ESLintEngine extends Engine {
if (userConfigInfo.getState() === UserConfigState.LEGACY_USER_CONFIG) {
this.emitLogEvent(LogLevel.Warn, getMessage('DetectedLegacyConfig',
userConfigInfo.getChosenUserConfigFile() ?? /* istanbul ignore next */ userConfigInfo.getChosenUserIgnoreFile()!));
this.emitTelemetryEvent('eslintLegacyConfigDetected', {
'eslint_engine_version': await this.getEngineVersion(),
'eslint8_engine_version': await this.delegateV8Engine.getEngineVersion()
});
return this.delegateV8Engine.describeRules(describeOptions);
}

Expand Down
18 changes: 18 additions & 0 deletions packages/code-analyzer-eslint-engine/test/end-to-end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
LogEvent,
LogLevel,
RuleDescription,
TelemetryEvent,
Violation,
Workspace
} from "@salesforce/code-analyzer-engine-api";
import path from "node:path";
import * as os from "node:os";
import process from "node:process";
import {ESLint8EnginePlugin} from "@salesforce/code-analyzer-eslint8-engine";

jest.setTimeout(30_000);

Expand Down Expand Up @@ -46,6 +48,8 @@ describe('End to end test', () => {
const defaultConfig: ConfigObject = await plugin.createEngineConfig(availableEngineNames[0], configValueExtractor);
const engine: Engine = await plugin.createEngine(availableEngineNames[0], defaultConfig);
const logEvents: LogEvent[] = [];
const telemetryEvents: TelemetryEvent[] = [];
engine.onEvent(EventType.TelemetryEvent, (e: TelemetryEvent) => telemetryEvents.push(e));
engine.onEvent(EventType.LogEvent, (e: LogEvent) => logEvents.push(e));
const workspace: Workspace = new Workspace('id', [path.resolve('.')]);
const ruleDescriptions: RuleDescription[] = await engine.describeRules({logFolder: os.tmpdir(), workspace: workspace});
Expand All @@ -68,6 +72,8 @@ describe('End to end test', () => {

const warnLogs: LogEvent[] = logEvents.filter(e => e.logLevel == LogLevel.Warn);
expect(warnLogs).toHaveLength(0);

expect(telemetryEvents).toHaveLength(0);
});

it('Test that we delegate to eslint v8 engine when user has specified legacy eslint config file', async () => {
Expand All @@ -80,7 +86,9 @@ describe('End to end test', () => {
const defaultConfig: ConfigObject = await plugin.createEngineConfig('eslint', configValueExtractor);
const engine: Engine = await plugin.createEngine('eslint', defaultConfig);
const logEvents: LogEvent[] = [];
const telemetryEvents: TelemetryEvent[] = [];
engine.onEvent(EventType.LogEvent, (e: LogEvent) => logEvents.push(e));
engine.onEvent(EventType.TelemetryEvent, (e: TelemetryEvent) => telemetryEvents.push(e));
const workspace: Workspace = new Workspace('id', [path.resolve('.')]);
const ruleDescriptions: RuleDescription[] = await engine.describeRules({logFolder: os.tmpdir(), workspace: workspace});
const recommendedRuleNames: string[] = ruleDescriptions.filter(rd => rd.tags.includes('Recommended')).map(rd => rd.name);
Expand All @@ -104,5 +112,15 @@ describe('End to end test', () => {
const warnLogs: LogEvent[] = logEvents.filter(e => e.logLevel == LogLevel.Warn);
expect(warnLogs).toHaveLength(1);
expect(warnLogs[0].message).toContain('Using ESLint v8 instead of ESLint v9');

expect(telemetryEvents).toHaveLength(1);
Comment thread
stephen-carter-at-sf marked this conversation as resolved.
expect(telemetryEvents[0]).toEqual({
"type": "TelemetryEvent",
"eventName": "eslintLegacyConfigDetected",
"data": {
"eslint_engine_version": await engine.getEngineVersion(),
"eslint8_engine_version": await (await new ESLint8EnginePlugin().createEngine("eslint", {})).getEngineVersion()
}
});
});
});
Loading