Skip to content

Commit

Permalink
refactor(container-runtime): Enable `@typescript-eslint/explicit-modu…
Browse files Browse the repository at this point in the history
…le-boundary-types` eslint rule and fix violations (#23597)

One in a series of PRs working towards migrating the package to our
`recommended` config.

Plus a couple of misc. comment syntax fixes/improvements.


[AB#3027](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/3027)
  • Loading branch information
Josmithr authored Jan 17, 2025
1 parent c16bc56 commit 43ce18b
Show file tree
Hide file tree
Showing 43 changed files with 291 additions and 223 deletions.
1 change: 1 addition & 0 deletions packages/runtime/container-runtime/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {

// #region TODO:AB#3027: remove overrides and upgrade config to `recommended`

"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-explicit-any": [
"error",
{
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/container-runtime/src/batchTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export const BindBatchTracker = (
logger: ITelemetryLoggerExt,
batchLengthThreshold: number = 1000,
batchCountSamplingRate: number = 1000,
) => new BatchTracker(batchEventEmitter, logger, batchLengthThreshold, batchCountSamplingRate);
): BatchTracker =>
new BatchTracker(batchEventEmitter, logger, batchLengthThreshold, batchCountSamplingRate);
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ export class BlobHandle extends FluidHandleBase<ArrayBufferLike> {
this.absolutePath = generateHandleContextPath(path, this.routeContext);
}

public attachGraph() {
public attachGraph(): void {
if (!this.attached) {
this.attached = true;
this.onAttachGraph?.();
}
}

public bind(handle: IFluidHandleInternal) {
public bind(handle: IFluidHandleInternal): void {
throw new Error("Cannot bind to blob handle");
}
}
Expand Down Expand Up @@ -598,7 +598,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
* submitted to runtime while disconnected.
* @param metadata - op metadata containing storage and/or local IDs
*/
public reSubmit(metadata: Record<string, unknown> | undefined) {
public reSubmit(metadata: Record<string, unknown> | undefined): void {
assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
const { localId, blobId }: { localId?: string; blobId?: string } = metadata;
assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
Expand All @@ -615,7 +615,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
return this.sendBlobAttachOp(localId, blobId);
}

public processBlobAttachMessage(message: ISequencedMessageEnvelope, local: boolean) {
public processBlobAttachMessage(message: ISequencedMessageEnvelope, local: boolean): void {
const localId = (message.metadata as IBlobMetadata | undefined)?.localId;
const blobId = (message.metadata as IBlobMetadata | undefined)?.blobId;

Expand Down Expand Up @@ -785,7 +785,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
throw error;
}

public setRedirectTable(table: Map<string, string>) {
public setRedirectTable(table: Map<string, string>): void {
assert(
this.runtime.attachState === AttachState.Detached,
0x252 /* "redirect table can only be set in detached container" */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const summarizeV1 = (
export const getStorageIds = (
redirectTable: Map<string, string | undefined>,
attachState: AttachState,
) => {
): Set<string> => {
const ids = new Set<string | undefined>(redirectTable.values());

// If we are detached, we will not have storage IDs, only undefined
Expand Down
34 changes: 17 additions & 17 deletions packages/runtime/container-runtime/src/channelCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function wrapContextForInnerChannel(
/**
* Returns the type of the given local data store from its package path.
*/
export function getLocalDataStoreType(localDataStore: LocalFluidDataStoreContext) {
export function getLocalDataStoreType(localDataStore: LocalFluidDataStoreContext): string {
return localDataStore.packagePath[localDataStore.packagePath.length - 1];
}

Expand Down Expand Up @@ -392,7 +392,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
* Not clear when it would be called and what it should do.
* Currently this API is called by context only for root data stores.
*/
public makeVisibleAndAttachGraph() {
public makeVisibleAndAttachGraph(): void {
this.parentContext.makeLocallyVisible();
}

Expand Down Expand Up @@ -595,7 +595,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
this.contexts.bind(id);
}

protected submitAttachChannelOp(localContext: LocalFluidDataStoreContext) {
protected submitAttachChannelOp(localContext: LocalFluidDataStoreContext): void {
const message = this.generateAttachMessage(localContext);
this.pendingAttach.set(localContext.id, message);
this.parentContext.submitMessage(ContainerMessageType.Attach, message, undefined);
Expand Down Expand Up @@ -672,7 +672,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
pkg: Readonly<string[]>,
contextCtor: new (props: ILocalDetachedFluidDataStoreContextProps) => T,
loadingGroupId?: string,
) {
): T {
assert(loadingGroupId !== "", 0x974 /* loadingGroupId should not be the empty string */);
const context = new contextCtor({
id,
Expand All @@ -699,12 +699,12 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
return context;
}

public get disposed() {
public get disposed(): boolean {
return this.disposeOnce.evaluated;
}
public readonly dispose = () => this.disposeOnce.value;
public readonly dispose = (): void => this.disposeOnce.value;

public reSubmit(type: string, content: unknown, localOpMetadata: unknown) {
public reSubmit(type: string, content: unknown, localOpMetadata: unknown): void {
switch (type) {
case ContainerMessageType.Attach:
case ContainerMessageType.Alias:
Expand All @@ -717,7 +717,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
}
}

protected reSubmitChannelOp(type: string, content: unknown, localOpMetadata: unknown) {
protected reSubmitChannelOp(type: string, content: unknown, localOpMetadata: unknown): void {
const envelope = content as IEnvelope;
const context = this.contexts.get(envelope.address);
// If the data store has been deleted, log an error and throw an error. If there are local changes for a
Expand All @@ -735,7 +735,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
context.reSubmit(innerContents.type, innerContents.content, localOpMetadata);
}

public rollback(type: string, content: unknown, localOpMetadata: unknown) {
public rollback(type: string, content: unknown, localOpMetadata: unknown): void {
assert(type === ContainerMessageType.FluidDataStoreOp, 0x8e8 /* type */);
const envelope = content as IEnvelope;
const context = this.contexts.get(envelope.address);
Expand Down Expand Up @@ -768,7 +768,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
}
}

protected async applyStashedChannelChannelOp(envelope: IEnvelope) {
protected async applyStashedChannelChannelOp(envelope: IEnvelope): Promise<unknown> {
const context = this.contexts.get(envelope.address);
// If the data store has been deleted, log an error and ignore this message. This helps prevent document
// corruption in case the data store that stashed the op is deleted.
Expand Down Expand Up @@ -854,7 +854,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
message: ISequencedDocumentMessage,
local: boolean,
localOpMetadata: unknown,
) {
): void {
this.processMessages({
envelope: message,
messagesContent: [
Expand Down Expand Up @@ -1096,7 +1096,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
return true;
}

public processSignal(messageArg: IInboundSignalMessage, local: boolean) {
public processSignal(messageArg: IInboundSignalMessage, local: boolean): void {
const envelope = messageArg.content as IEnvelope;
const fluidDataStoreId = envelope.address;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -1123,7 +1123,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
context.processSignal(message, local);
}

public setConnectionState(connected: boolean, clientId?: string) {
public setConnectionState(connected: boolean, clientId?: string): void {
for (const [fluidDataStoreId, context] of this.contexts) {
try {
context.setConnectionState(connected, clientId);
Expand Down Expand Up @@ -1333,7 +1333,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
* After GC has run, called to notify this Container's data stores of routes that are used in it.
* @param usedRoutes - The routes that are used in all data stores in this Container.
*/
public updateUsedRoutes(usedRoutes: readonly string[]) {
public updateUsedRoutes(usedRoutes: readonly string[]): void {
// Get a map of data store ids to routes used in it.
const usedDataStoreRoutes = unpackChildNodesUsedRoutes(usedRoutes);

Expand All @@ -1351,7 +1351,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
}
}

public deleteChild(dataStoreId: string) {
public deleteChild(dataStoreId: string): void {
const dataStoreContext = this.contexts.get(dataStoreId);
assert(dataStoreContext !== undefined, 0x2d7 /* No data store with specified id */);

Expand Down Expand Up @@ -1423,7 +1423,7 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
*
* @param tombstonedRoutes - The routes that are tombstones in all data stores in this Container.
*/
public updateTombstonedRoutes(tombstonedRoutes: readonly string[]) {
public updateTombstonedRoutes(tombstonedRoutes: readonly string[]): void {
const tombstonedDataStoresSet: Set<string> = new Set();
for (const route of tombstonedRoutes) {
const pathParts = route.split("/");
Expand Down Expand Up @@ -1637,7 +1637,7 @@ export class ChannelCollectionFactory<T extends ChannelCollection = ChannelColle
this.IFluidDataStoreRegistry = new FluidDataStoreRegistry(registryEntries);
}

public get IFluidDataStoreFactory() {
public get IFluidDataStoreFactory(): ChannelCollectionFactory<T> {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface IContainerHandleContextRuntime {
}

export class ContainerFluidHandleContext implements IFluidHandleContext {
public get IFluidHandleContext() {
public get IFluidHandleContext(): IFluidHandleContext {
return this;
}
public readonly absolutePath: string;
Expand All @@ -37,7 +37,7 @@ export class ContainerFluidHandleContext implements IFluidHandleContext {
throw new Error("can't attach container runtime form within container!");
}

public get isAttached() {
public get isAttached(): boolean {
return this.runtime.attachState !== AttachState.Detached;
}

Expand Down
Loading

0 comments on commit 43ce18b

Please sign in to comment.