Skip to content

Commit

Permalink
eslint(telemetry-utils): Prefix telemetry-utils before enabling no-un…
Browse files Browse the repository at this point in the history
…checked-record-access (#23428)

eslint(telemetry-utils): Prefix telemetry-utils before enabling
no-unchecked-record-access

[AB#25378](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/25378)
  • Loading branch information
RishhiB authored Jan 6, 2025
1 parent abad97f commit 0f6b54d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/utils/telemetry-utils/src/errorLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ function copyProps(
target: ITelemetryPropertiesExt | LoggingError,
source: ITelemetryPropertiesExt,
): void {
for (const key of Object.keys(source)) {
for (const [key, value] of Object.entries(source)) {
if (target[key] === undefined) {
target[key] = source[key];
target[key] = value;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/utils/telemetry-utils/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@ export abstract class TelemetryLogger implements ITelemetryLoggerExt {
}
for (const props of properties) {
if (props !== undefined) {
for (const key of Object.keys(props)) {
for (const [key, getterOrValue] of Object.entries(props)) {
if (eventLike[key] !== undefined) {
continue;
}
const getterOrValue = props[key];
// If this throws, hopefully it is handled elsewhere
const value =
typeof getterOrValue === "function" ? getterOrValue() : getterOrValue;
Expand Down Expand Up @@ -326,8 +325,7 @@ export class TaggedLoggerAdapter implements ITelemetryBaseLogger {
category: eventWithTagsMaybe.category,
eventName: eventWithTagsMaybe.eventName,
};
for (const key of Object.keys(eventWithTagsMaybe)) {
const taggableProp = eventWithTagsMaybe[key];
for (const [key, taggableProp] of Object.entries(eventWithTagsMaybe)) {
const { value, tag } =
typeof taggableProp === "object"
? taggableProp
Expand Down
7 changes: 6 additions & 1 deletion packages/utils/telemetry-utils/src/mockLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type ITelemetryBaseEvent,
type ITelemetryBaseLogger,
LogLevel,
type Tagged,
} from "@fluidframework/core-interfaces";
import { assert } from "@fluidframework/core-utils/internal";

Expand All @@ -15,6 +16,7 @@ import type {
ITelemetryEventExt,
ITelemetryLoggerExt,
ITelemetryPropertiesExt,
TelemetryEventPropertyTypeExt,
} from "./telemetryTypes.js";

/**
Expand Down Expand Up @@ -334,7 +336,10 @@ function matchObjects(
expected: ITelemetryPropertiesExt,
): boolean {
for (const [expectedKey, expectedValue] of Object.entries(expected)) {
const actualValue = actual[expectedKey];
const actualValue:
| TelemetryEventPropertyTypeExt
| Tagged<TelemetryEventPropertyTypeExt>
| undefined = actual[expectedKey];
if (
!Array.isArray(expectedValue) &&
expectedValue !== null &&
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/telemetry-utils/src/test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const getMockStore = (settings: Record<string, string>): Storage => {
return {
getItem: (key: string): string | null => {
ops.push(key);
return settings[key];
// eslint-disable-next-line unicorn/no-null
return settings[key] ?? null;
},
getOps: (): Readonly<string[]> => ops,
length: Object.keys(settings).length,
Expand Down
8 changes: 3 additions & 5 deletions packages/utils/telemetry-utils/src/test/errorLogging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ const annotationCases: Record<string, IFluidErrorAnnotations> = {
describe("normalizeError", () => {
describe("Valid Errors (Legacy and Current)", () => {
for (const annotationCase of Object.keys(annotationCases)) {
const annotations = annotationCases[annotationCase];
const annotations: IFluidErrorAnnotations | undefined = annotationCases[annotationCase];
it(`Valid Fluid Error - untouched (annotations: ${annotationCase})`, () => {
// Arrange
const fluidError = new TestFluidError({ errorType: "et1", message: "m1" });
Expand Down Expand Up @@ -914,11 +914,9 @@ describe("normalizeError", () => {
expected.withExpectedTelemetryProps({ stack: inputStack });
}
}
for (const annotationCase of Object.keys(annotationCases)) {
const annotations = annotationCases[annotationCase];
for (const [annotationCase, annotations] of Object.entries(annotationCases)) {
let doneOnceForThisAnnotationCase = false;
for (const caseName of Object.keys(testCases)) {
const getTestCase = testCases[caseName];
for (const [caseName, getTestCase] of Object.entries(testCases)) {
if (!doneOnceForThisAnnotationCase) {
doneOnceForThisAnnotationCase = true;
// Each test case only differs by what stack/error are. Test the rest only once per annotation case.
Expand Down

0 comments on commit 0f6b54d

Please sign in to comment.