Skip to content

Commit

Permalink
refactor(runtime-definitions): Move to recommended lint config (#23555)
Browse files Browse the repository at this point in the history
## Description

Moves the runtime-definitions package to use the recommended lint
configuration. Locally disabled rules for use of `any` in a few places,
and replaced one in a `@sealed` interface with `unknown`, additionally
updating the code that declares listeners for the relevant event.
Somehow TS doesn't complain about the mismatching listener signatures. I
did not try to investigate why.

Co-authored-by: Joshua Smithrud <54606601+Josmithr@users.noreply.github.com>
  • Loading branch information
alexvy86 and Josmithr authored Jan 15, 2025
1 parent 6c2786a commit aae275e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 42 deletions.
61 changes: 29 additions & 32 deletions packages/runtime/container-runtime/src/batchTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,38 @@ export class BatchTracker {
this.trackedBatchCount++;
});

this.batchEventEmitter.on(
"batchEnd",
(error: any | undefined, message: BatchTrackerMessage) => {
assert(
this.startBatchSequenceNumber !== undefined &&
this.batchProcessingStartTimeStamp !== undefined,
0x2ba /* "batchBegin must fire before batchEnd" */,
);
this.batchEventEmitter.on("batchEnd", (error: unknown, message: BatchTrackerMessage) => {
assert(
this.startBatchSequenceNumber !== undefined &&
this.batchProcessingStartTimeStamp !== undefined,
0x2ba /* "batchBegin must fire before batchEnd" */,
);

const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;
if (length >= batchLengthThreshold) {
this.logger.sendPerformanceEvent({
eventName: "LengthTooBig",
length,
threshold: batchLengthThreshold,
batchEndSequenceNumber: message.sequenceNumber,
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
batchError: error !== undefined,
});
}
const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;
if (length >= batchLengthThreshold) {
this.logger.sendPerformanceEvent({
eventName: "LengthTooBig",
length,
threshold: batchLengthThreshold,
batchEndSequenceNumber: message.sequenceNumber,
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
batchError: error !== undefined,
});
}

if (this.trackedBatchCount % batchCountSamplingRate === 0) {
this.logger.sendPerformanceEvent({
eventName: "Length",
length,
samplingRate: batchCountSamplingRate,
batchEndSequenceNumber: message.sequenceNumber,
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
});
}
if (this.trackedBatchCount % batchCountSamplingRate === 0) {
this.logger.sendPerformanceEvent({
eventName: "Length",
length,
samplingRate: batchCountSamplingRate,
batchEndSequenceNumber: message.sequenceNumber,
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
});
}

this.startBatchSequenceNumber = undefined;
this.batchProcessingStartTimeStamp = undefined;
},
);
this.startBatchSequenceNumber = undefined;
this.batchProcessingStartTimeStamp = undefined;
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/container-runtime/src/deltaScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class DeltaScheduler {
}
};

private readonly batchEnd = (error: any, message: ISequencedDocumentMessage) => {
private readonly batchEnd = (error: unknown, message: ISequencedDocumentMessage) => {
if (this.schedulingLog) {
this.schedulingLog.numberOfBatchesProcessed++;
this.schedulingLog.lastSequenceNumber = message.sequenceNumber;
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/runtime-definitions/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
},
extends: ["@fluidframework/eslint-config-fluid/minimal-deprecated", "prettier"],
extends: ["@fluidframework/eslint-config-fluid", "prettier"],
plugins: ["deprecation"],
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface IContainerRuntimeBase extends IEventProvider<IContainerRuntimeB
// @alpha @sealed (undocumented)
export interface IContainerRuntimeBaseEvents extends IEvent {
(event: "batchBegin", listener: (op: Omit<ISequencedDocumentMessage, "contents">) => void): any;
(event: "batchEnd", listener: (error: any, op: Omit<ISequencedDocumentMessage, "contents">) => void): any;
(event: "batchEnd", listener: (error: unknown, op: Omit<ISequencedDocumentMessage, "contents">) => void): any;
(event: "op", listener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void): any;
// (undocumented)
(event: "signal", listener: (message: IInboundSignalMessage, local: boolean) => void): any;
Expand Down
10 changes: 9 additions & 1 deletion packages/runtime/runtime-definitions/src/dataStoreContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface IContainerRuntimeBaseEvents extends IEvent {
*/
(
event: "batchEnd",
listener: (error: any, op: Omit<ISequencedDocumentMessage, "contents">) => void,
listener: (error: unknown, op: Omit<ISequencedDocumentMessage, "contents">) => void,
);
/**
* Indicates that an incoming op has been processed.
Expand Down Expand Up @@ -382,8 +382,10 @@ export interface IFluidDataStoreChannel extends IDisposable {
* @param content - The content of the original message.
* @param localOpMetadata - The local metadata associated with the original message.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
reSubmit(type: string, content: any, localOpMetadata: unknown);

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
applyStashedOp(content: any): Promise<unknown>;

/**
Expand All @@ -392,6 +394,7 @@ export interface IFluidDataStoreChannel extends IDisposable {
* @param content - The content of the original message.
* @param localOpMetadata - The local metadata associated with the original message.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
rollback?(type: string, content: any, localOpMetadata: unknown): void;

/**
Expand Down Expand Up @@ -439,6 +442,7 @@ export interface IPendingMessagesState {
export interface IFluidParentContext
extends IProvideFluidHandleContext,
Partial<IProvideFluidDataStoreRegistry> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
readonly options: Record<string | number, any>;
readonly clientId: string | undefined;
readonly connected: boolean;
Expand Down Expand Up @@ -491,6 +495,7 @@ export interface IFluidParentContext
* the server. This will be sent back when this message is received back from the server. This is also sent if
* we are asked to resubmit the message.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
submitMessage(type: string, content: any, localOpMetadata: unknown): void;

/**
Expand Down Expand Up @@ -578,6 +583,9 @@ export interface IFluidDataStoreContext extends IFluidParentContext {
/**
* @deprecated 0.16 Issue #1635, #3631
*/
// Seems like this can be removed now; the issues mentioned in the @deprecated tag are about _createDataStoreWithProps
// which we finally removed in FF 2.20 (https://github.com/microsoft/FluidFramework/pull/22996).
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
readonly createProps?: any;

/**
Expand Down
26 changes: 20 additions & 6 deletions packages/runtime/runtime-definitions/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IEnvelope {
/**
* The contents of the envelope
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO (#28746): breaking change
contents: any;
}

Expand Down Expand Up @@ -67,6 +68,7 @@ export interface IAttachMessage {
* @alpha
*/
export type InboundAttachMessage = Omit<IAttachMessage, "snapshot"> & {
// eslint-disable-next-line @rushstack/no-new-null -- TODO: breaking change; protocol might even explicitly use null
snapshot: IAttachMessage["snapshot"] | null;
};

Expand All @@ -90,11 +92,17 @@ export type ISequencedMessageEnvelope = Omit<
* @sealed
*/
export interface IRuntimeMessagesContent {
/** The contents of the message, i.e., the payload */
/**
* The contents of the message, i.e., the payload
*/
readonly contents: unknown;
/** The local metadata associated with the original message that was submitted */
/**
* The local metadata associated with the original message that was submitted
*/
readonly localOpMetadata: unknown;
/** The client sequence number of the message */
/**
* The client sequence number of the message
*/
readonly clientSequenceNumber: number;
}

Expand All @@ -105,10 +113,16 @@ export interface IRuntimeMessagesContent {
* @sealed
*/
export interface IRuntimeMessageCollection {
/** The envelope for all the messages in the collection */
/**
* The envelope for all the messages in the collection
*/
readonly envelope: ISequencedMessageEnvelope;
/** Whether these messages were originally generated by the client processing it */
/**
* Whether these messages were originally generated by the client processing them
*/
readonly local: boolean;
/** The contents of the messages in the collection */
/**
* The contents of the messages in the collection
*/
readonly messagesContent: readonly IRuntimeMessagesContent[];
}

0 comments on commit aae275e

Please sign in to comment.