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

fix: [#4684] ESLint issues in botframework-streaming #4825

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 3 additions & 8 deletions libraries/botframework-streaming/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const onlyWarn = require("eslint-plugin-only-warn");
const sharedConfig = require("../../eslint.config.cjs")
const sharedConfig = require('../../eslint.config.cjs');

module.exports = [
...sharedConfig,
{
ignores: ["**/es5/"],
ignores: ['**/es5/'],
},
{
plugins: {
"only-warn": onlyWarn,
},
}]
];
1 change: 0 additions & 1 deletion libraries/botframework-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dependencies": {
"@types/node": "18.19.47",
"@types/ws": "^6.0.3",
"eslint-plugin-only-warn": "^1.1.0",
"uuid": "^10.0.0",
"ws": "^7.5.10"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class PayloadAssembler {
* @param streamManager The [StreamManager](xref:botframework-streaming.StreamManager) managing the stream being assembled.
* @param params Parameters for a streaming assembler.
*/
constructor(private readonly streamManager: StreamManager, params: IAssemblerParams) {
constructor(
private readonly streamManager: StreamManager,
params: IAssemblerParams,
) {
if (params.header) {
this.id = params.header.id;
this.payloadType = params.header.payloadType;
Expand Down Expand Up @@ -141,7 +144,7 @@ export class PayloadAssembler {

private async processStreams(
responsePayload: IResponsePayload | IRequestPayload,
receiveResponse: IReceiveResponse | IReceiveRequest
receiveResponse: IReceiveResponse | IReceiveRequest,
): Promise<void> {
responsePayload.streams?.forEach((responseStream) => {
// There was a bug in how streams were handled. In .NET, the StreamDescription definiton mapped the
Expand All @@ -151,7 +154,7 @@ export class PayloadAssembler {
// .NET code:
// https://github.com/microsoft/botbuilder-dotnet/blob/a79036ddf6625ec3fd68a6f7295886eb7831bc1c/libraries/Microsoft.Bot.Streaming/Payloads/Models/StreamDescription.cs#L28-L29
const contentType =
((responseStream as unknown) as Record<string, string>).type ?? responseStream.contentType;
(responseStream as unknown as Record<string, string>).type ?? responseStream.contentType;

const contentAssembler = this.streamManager.getPayloadAssembler(responseStream.id);

Expand Down
18 changes: 9 additions & 9 deletions libraries/botframework-streaming/src/contentStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class ContentStream {
return <T>JSON.parse(stringToParse);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async readAll(): Promise<Record<string, any>> {
// do a read-all
const allData: INodeBuffer[] = [];
Expand All @@ -107,14 +106,15 @@ export class ContentStream {

if (count < this.length) {
const readToEnd = new Promise<boolean>((resolve): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callback = (cs: ContentStream) => (chunk: any): void => {
allData.push(chunk);
count += (chunk as INodeBuffer).length;
if (count === cs.length) {
resolve(true);
}
};
const callback =
(cs: ContentStream) =>
(chunk: any): void => {
allData.push(chunk);
count += (chunk as INodeBuffer).length;
if (count === cs.length) {
resolve(true);
}
};

stream.subscribe(callback(this));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CancelDisassembler {
constructor(
private readonly sender: PayloadSender,
private readonly id: string,
private readonly payloadType: PayloadTypes
private readonly payloadType: PayloadTypes,
) {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export abstract class PayloadDisassembler {
* @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) used to send the disassembled payload chunks.
* @param id The ID of this disassembler.
*/
constructor(private readonly sender: PayloadSender, private readonly id: string) {}
constructor(
private readonly sender: PayloadSender,
private readonly id: string,
) {}

/**
* Serializes the item into the [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) that exposes the stream and length of the result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export class RequestDisassembler extends PayloadDisassembler {
* @param id The ID of this disassembler.
* @param request The request to be disassembled.
*/
constructor(sender: PayloadSender, id: string, public request?: StreamingRequest) {
constructor(
sender: PayloadSender,
id: string,
public request?: StreamingRequest,
) {
super(sender, id);
}

Expand Down
5 changes: 4 additions & 1 deletion libraries/botframework-streaming/src/httpContentStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class HttpContent {
* @param headers The Streaming Http content header definition.
* @param stream The stream of buffered data.
*/
constructor(public headers: IHttpContentHeaders, private readonly stream: SubscribableStream) {}
constructor(
public headers: IHttpContentHeaders,
private readonly stream: SubscribableStream,
) {}

/**
* Gets the data contained within this [HttpContent](xref:botframework-streaming.HttpContent).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface IBrowserFileReader {
/* eslint-disable @typescript-eslint/no-explicit-any */
result: any;
onload: (event: any) => void;
readAsArrayBuffer: (blobOrFile: any) => void;
/* eslint-enable @typescript-eslint/no-explicit-any */
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface IBrowserWebSocket {
/* eslint-disable @typescript-eslint/no-explicit-any */
onclose: (event: any) => void;
onerror: (event: any) => void;
onmessage: (event: any) => void;
onopen: (event: any) => void;
send(buffer: any): void;
/* eslint-enable @typescript-eslint/no-explicit-any */
readyState: number;
close(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface IEventEmitter {
/* eslint-disable @typescript-eslint/no-explicit-any */
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
emit(event: string | symbol, ...args: any[]): boolean;
off(event: string | symbol, listener: (...args: any[]) => void): this;
Expand All @@ -21,14 +20,11 @@ export interface IEventEmitter {
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
/* eslint-enable @typescript-eslint/no-explicit-any */
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
/* eslint-disable @typescript-eslint/ban-types */
listeners(event: string | symbol): Function[];
rawListeners(event: string | symbol): Function[];
/* eslint-enable @typescript-eslint/ban-types */
listeners(event: string | symbol): ((...args: any[]) => void)[];
rawListeners(event: string | symbol): ((...args: any[]) => void)[];
listenerCount(type: string | symbol): number;
eventNames(): Array<string | symbol>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ export type BufferEncoding =
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface INodeBuffer extends Uint8Array {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor: any;
write(string: string, offset?: number, length?: number, encoding?: string): number;
toString(encoding?: string, start?: number, end?: number): string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toJSON(): { type: 'Buffer'; data: any[] };
equals(otherBuffer: Uint8Array): boolean;
compare(
otherBuffer: Uint8Array,
targetStart?: number,
targetEnd?: number,
sourceStart?: number,
sourceEnd?: number
sourceEnd?: number,
): number;
copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
slice(start?: number, end?: number): this;
Expand Down Expand Up @@ -92,7 +90,6 @@ export interface INodeBuffer extends Uint8Array {
writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
fill(value: any, offset?: number, end?: number): this;
indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number;
lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
/**
* @module botframework-streaming
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ export interface INodeIncomingMessage {
/**
* Optional. The request headers.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
headers?: any;

/**
* Optional. The request method.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
method?: any;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
/**
* @module botframework-streaming
*/
Expand Down
3 changes: 0 additions & 3 deletions libraries/botframework-streaming/src/interfaces/ISocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export interface ISocket {
write(buffer: INodeBuffer);
connect(serverAddress: string): Promise<void>;
close();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setOnMessageHandler(handler: (x: any) => void);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setOnErrorHandler(handler: (x: any) => void);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setOnCloseHandler(handler: (x: any) => void);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class NamedPipeClient implements IStreamingTransportClient {
this._requestHandler,
this._requestManager,
this._sender,
this._receiver
this._receiver,
);
}

Expand Down Expand Up @@ -83,7 +83,6 @@ export class NamedPipeClient implements IStreamingTransportClient {
return this._protocolAdapter.sendRequest(request);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private onConnectionDisconnected(sender: Record<string, unknown>, args: any): void {
if (!this._isDisconnecting) {
this._isDisconnecting = true;
Expand All @@ -101,7 +100,7 @@ export class NamedPipeClient implements IStreamingTransportClient {
.then((): void => {})
.catch((error): void => {
throw new Error(
`Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `
`Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export class NamedPipeServer implements IStreamingTransportServer {
* @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this client.
* @param autoReconnect Deprecated: Automatic reconnection is the default behavior.
*/
constructor(private readonly baseName: string, requestHandler?: RequestHandler, autoReconnect?: boolean) {
constructor(
private readonly baseName: string,
requestHandler?: RequestHandler,
autoReconnect?: boolean,
) {
if (!baseName) {
throw new TypeError('NamedPipeServer: Missing baseName parameter');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver
private _activeOffset = 0;
private _activeReceiveCount = 0;
private _activeReceiveResolve: (resolve: INodeBuffer) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _activeReceiveReject: (reason?: any) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class PayloadReceiver {
*/
subscribe(
getStream: (header: IHeader) => SubscribableStream,
receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void
receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void,
): void {
this._getStream = getStream;
this._receiveAction = receiveAction;
Expand Down Expand Up @@ -86,7 +86,7 @@ export class PayloadReceiver {
let readSoFar = 0;
while (readSoFar < PayloadConstants.MaxHeaderLength) {
this._receiveHeaderBuffer = await this._receiver.receive(
PayloadConstants.MaxHeaderLength - readSoFar
PayloadConstants.MaxHeaderLength - readSoFar,
);

if (this._receiveHeaderBuffer) {
Expand All @@ -108,7 +108,7 @@ export class PayloadReceiver {
) {
const count = Math.min(
header.payloadLength - bytesActuallyRead,
PayloadConstants.MaxPayloadLength
PayloadConstants.MaxPayloadLength,
);
this._receivePayloadBuffer = await this._receiver.receive(count);
bytesActuallyRead += this._receivePayloadBuffer.byteLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

import { TransportDisconnectedEvent } from './transportDisconnectedEvent';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TransportDisconnectedEventHandler = (sender: any, e: TransportDisconnectedEvent) => void;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class HeaderSerializer {
this.headerLengthPadder(header.payloadLength, this.LengthLength, '0'),
this.LengthOffset,
this.LengthLength,
this.Encoding
this.Encoding,
);
buffer.write(this.Delimiter, this.LengthDelimeterOffset, 1, this.Encoding);
buffer.write(header.id, this.IdOffset);
Expand Down
1 change: 0 additions & 1 deletion libraries/botframework-streaming/src/payloads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ export * from './payloadAssemblerManager';
export * from './payloadTypes';
export * from './requestManager';
export * from './sendOperations';
export * from './streamManager';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayloadAssemblerManager {
constructor(
private readonly streamManager: StreamManager,
private readonly onReceiveResponse: (id: string, receiveResponse: IReceiveResponse) => Promise<void>,
private readonly onReceiveRequest: (id: string, receiveRequest: IReceiveRequest) => Promise<void>
private readonly onReceiveRequest: (id: string, receiveRequest: IReceiveRequest) => Promise<void>,
) {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { IReceiveResponse } from '../interfaces';
class PendingRequest {
requestId: string;
resolve: (response: IReceiveResponse) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reject: (reason?: any) => void;
}

Expand Down
16 changes: 6 additions & 10 deletions libraries/botframework-streaming/src/payloads/sendOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ export class SendOperations {
await disassembler.disassemble();

if (request.streams) {
request.streams.forEach(
async (contentStream): Promise<void> => {
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble();
}
);
request.streams.forEach(async (contentStream): Promise<void> => {
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble();
});
}
}

Expand All @@ -61,11 +59,9 @@ export class SendOperations {
await disassembler.disassemble();

if (response.streams) {
response.streams.forEach(
async (contentStream): Promise<void> => {
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble();
}
);
response.streams.forEach(async (contentStream): Promise<void> => {
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble();
});
}
}

Expand Down
Loading
Loading