Skip to content

Commit 93a90ec

Browse files
CHANGE: @W-19148450@: Add telemetry for detecting eslint legacy config (#317)
1 parent d97e34d commit 93a90ec

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/code-analyzer-eslint-engine/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/code-analyzer-eslint-engine",
33
"description": "Plugin package that adds 'eslint' as an engine into Salesforce Code Analyzer",
4-
"version": "0.27.0",
4+
"version": "0.28.0-SNAPSHOT",
55
"author": "The Salesforce Code Analyzer Team",
66
"license": "BSD-3-Clause",
77
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
@@ -76,4 +76,4 @@
7676
"!src/index.ts"
7777
]
7878
}
79-
}
79+
}

packages/code-analyzer-eslint-engine/src/engine.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export class ESLintEngine extends Engine {
6868
if (userConfigInfo.getState() === UserConfigState.LEGACY_USER_CONFIG) {
6969
this.emitLogEvent(LogLevel.Warn, getMessage('DetectedLegacyConfig',
7070
userConfigInfo.getChosenUserConfigFile() ?? /* istanbul ignore next */ userConfigInfo.getChosenUserIgnoreFile()!));
71+
this.emitTelemetryEvent('eslintLegacyConfigDetected', {
72+
'eslint_engine_version': await this.getEngineVersion(),
73+
'eslint8_engine_version': await this.delegateV8Engine.getEngineVersion()
74+
});
7175
return this.delegateV8Engine.describeRules(describeOptions);
7276
}
7377

packages/code-analyzer-eslint-engine/test/end-to-end.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import {
99
LogEvent,
1010
LogLevel,
1111
RuleDescription,
12+
TelemetryEvent,
1213
Violation,
1314
Workspace
1415
} from "@salesforce/code-analyzer-engine-api";
1516
import path from "node:path";
1617
import * as os from "node:os";
1718
import process from "node:process";
19+
import {ESLint8EnginePlugin} from "@salesforce/code-analyzer-eslint8-engine";
1820

1921
jest.setTimeout(30_000);
2022

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

6973
const warnLogs: LogEvent[] = logEvents.filter(e => e.logLevel == LogLevel.Warn);
7074
expect(warnLogs).toHaveLength(0);
75+
76+
expect(telemetryEvents).toHaveLength(0);
7177
});
7278

7379
it('Test that we delegate to eslint v8 engine when user has specified legacy eslint config file', async () => {
@@ -80,7 +86,9 @@ describe('End to end test', () => {
8086
const defaultConfig: ConfigObject = await plugin.createEngineConfig('eslint', configValueExtractor);
8187
const engine: Engine = await plugin.createEngine('eslint', defaultConfig);
8288
const logEvents: LogEvent[] = [];
89+
const telemetryEvents: TelemetryEvent[] = [];
8390
engine.onEvent(EventType.LogEvent, (e: LogEvent) => logEvents.push(e));
91+
engine.onEvent(EventType.TelemetryEvent, (e: TelemetryEvent) => telemetryEvents.push(e));
8492
const workspace: Workspace = new Workspace('id', [path.resolve('.')]);
8593
const ruleDescriptions: RuleDescription[] = await engine.describeRules({logFolder: os.tmpdir(), workspace: workspace});
8694
const recommendedRuleNames: string[] = ruleDescriptions.filter(rd => rd.tags.includes('Recommended')).map(rd => rd.name);
@@ -104,5 +112,15 @@ describe('End to end test', () => {
104112
const warnLogs: LogEvent[] = logEvents.filter(e => e.logLevel == LogLevel.Warn);
105113
expect(warnLogs).toHaveLength(1);
106114
expect(warnLogs[0].message).toContain('Using ESLint v8 instead of ESLint v9');
115+
116+
expect(telemetryEvents).toHaveLength(1);
117+
expect(telemetryEvents[0]).toEqual({
118+
"type": "TelemetryEvent",
119+
"eventName": "eslintLegacyConfigDetected",
120+
"data": {
121+
"eslint_engine_version": await engine.getEngineVersion(),
122+
"eslint8_engine_version": await (await new ESLint8EnginePlugin().createEngine("eslint", {})).getEngineVersion()
123+
}
124+
});
107125
});
108126
});

0 commit comments

Comments
 (0)