Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 6, 2025
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RishhiB, this file change should be redone. T | undefined pattern doesn't work as intended. Other changes are okay.

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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah is this really what the formatter wants? I am not a fan of how the RHS of the = is on the same line as the end of that multi-line type. Weird, oh well.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale here? Is the calling code prepared to handle null instead of undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, getItem is typed to string | null, but returning settings[key] results in a type of string | undefined, so I just force it to null if its undefined

},
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
Loading