Skip to content

Commit

Permalink
Fix ESLint in botframework-streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut committed Nov 14, 2024
1 parent 7693a09 commit 60fed56
Show file tree
Hide file tree
Showing 34 changed files with 384 additions and 408 deletions.
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 @@ -18,7 +18,6 @@ export interface IBrowserWebSocket {
onmessage: (event: any) => void;
onopen: (event: any) => void;
send(buffer: any): void;

readyState: number;
close(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,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;

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 @@ -29,7 +29,6 @@ export interface INodeBuffer extends Uint8Array {
constructor: any;
write(string: string, offset?: number, length?: number, encoding?: string): number;
toString(encoding?: string, start?: number, end?: number): string;

toJSON(): { type: 'Buffer'; data: any[] };
equals(otherBuffer: Uint8Array): boolean;
compare(
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.
*/

headers?: any;

/**
* Optional. The request method.
*/

method?: any;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @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();

setOnMessageHandler(handler: (x: any) => void);

setOnErrorHandler(handler: (x: any) => void);

setOnCloseHandler(handler: (x: any) => void);
}
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;

private _activeReceiveReject: (reason?: any) => void;

/**
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 @@ -13,7 +13,6 @@ import { IReceiveResponse } from '../interfaces';
class PendingRequest {
requestId: string;
resolve: (response: IReceiveResponse) => void;

reject: (reason?: any) => void;
}

Expand Down
1 change: 0 additions & 1 deletion libraries/botframework-streaming/src/streamingRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class StreamingRequest {
*
* @param body The JSON text to write to the body of the streamingRequest.
*/

setBody(body: any): void {
if (typeof body === 'string') {
const stream = new SubscribableStream();
Expand Down
1 change: 0 additions & 1 deletion libraries/botframework-streaming/src/streamingResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class StreamingResponse {
*
* @param body The JSON text to write to the body of the streaming response.
*/

setBody(body: any): void {
const stream = new SubscribableStream();
stream.write(JSON.stringify(body), 'utf8');
Expand Down
3 changes: 0 additions & 3 deletions libraries/botframework-streaming/src/subscribableStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class SubscribableStream extends Duplex {
length = 0;

private readonly bufferList: Buffer[] = [];

private _onData: (chunk: any) => void;

/**
Expand All @@ -34,7 +33,6 @@ export class SubscribableStream extends Duplex {
* @param _encoding The encoding. Unused in the implementation of Duplex.
* @param callback Callback for when this chunk of data is flushed.
*/

_write(chunk: any, _encoding: string, callback: (error?: Error | null) => void): void {
const buffer = Buffer.from(chunk);
this.bufferList.push(buffer);
Expand Down Expand Up @@ -72,7 +70,6 @@ export class SubscribableStream extends Duplex {
*
* @param onData Callback to be called when onData is executed.
*/

subscribe(onData: (chunk: any) => void): void {
this._onData = onData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function createNodeServer(callback?: ConnectionListener): INodeServer {
* @returns a server factory function
*/
export function getServerFactory(): (callback?: ConnectionListener) => INodeServer {
if (typeof require !== undefined) {
if (typeof require !== 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('net').Server;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class BrowserWebSocket implements ISocket {
*/
async connect(serverAddress: string): Promise<void> {
let resolver: (value: void | PromiseLike<void>) => void;

let rejector: (reason?: any) => void;

if (!this.webSocket) {
Expand Down Expand Up @@ -83,7 +82,6 @@ export class BrowserWebSocket implements ISocket {
*
* @param handler The callback to handle the "message" event.
*/

setOnMessageHandler(handler: (x: any) => void): void {
const bufferKey = 'buffer';
const packets = [];
Expand All @@ -110,7 +108,6 @@ export class BrowserWebSocket implements ISocket {
*
* @param handler The callback to handle the "error" event.
*/

setOnErrorHandler(handler: (x: any) => void): void {
this.webSocket.onerror = (error): void => {
if (error) {
Expand All @@ -124,7 +121,6 @@ export class BrowserWebSocket implements ISocket {
*
* @param handler The callback to handle the "close" event.
*/

setOnCloseHandler(handler: (x: any) => void): void {
this.webSocket.onclose = handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class NodeWebSocket implements ISocket {
req.on('upgrade', (res, socket, head): void => {
// @types/ws does not contain the signature for completeUpgrade
// https://github.com/websockets/ws/blob/0a612364e69fc07624b8010c6873f7766743a8e3/lib/websocket-server.js#L269

(this.wsServer as any).completeUpgrade(wskey, undefined, res, socket, head, (websocket): void => {
this.wsSocket = websocket;
});
Expand All @@ -143,7 +142,6 @@ export class NodeWebSocket implements ISocket {
*
* @param handler The callback to handle the "message" event.
*/

setOnMessageHandler(handler: (x: any) => void): void {
this.wsSocket.on('message', handler);
}
Expand All @@ -165,7 +163,6 @@ export class NodeWebSocket implements ISocket {
*
* @param handler The callback to handle the "close" event.
*/

setOnCloseHandler(handler: (x: any) => void): void {
this.wsSocket.on('close', handler);
}
Expand All @@ -175,7 +172,6 @@ export class NodeWebSocket implements ISocket {
*
* @param handler The callback to handle the "error" event.
*/

setOnErrorHandler(handler: (x: any) => void): void {
this.wsSocket.on('error', (error): void => {
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver
private _active: INodeBuffer;
private _activeOffset = 0;
private _activeReceiveResolve: (resolve: INodeBuffer) => void;

private _activeReceiveReject: (reason?: any) => void;
private _activeReceiveCount = 0;

Expand Down
26 changes: 26 additions & 0 deletions libraries/botframework-streaming/tests/CancelDisassembler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { expect } = require('chai');
const { CancelDisassembler } = require('../lib/disassemblers');
const { PayloadSender } = require('../lib/payloadTransport');
const { PayloadTypes } = require('../lib/payloads');

describe('CancelDisassembler', function () {
it('constructs correctly.', function () {
const sender = new PayloadSender();
const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream);

expect(cd.id).to.equal('42');
expect(cd.payloadType).to.equal(PayloadTypes.cancelStream);
expect(cd.sender).to.equal(sender);
});

it('sends payload without throwing.', function () {
const sender = new PayloadSender();
const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream);

expect(cd.id).to.equal('42');
expect(cd.payloadType).to.equal(PayloadTypes.cancelStream);
expect(cd.sender).to.equal(sender);

expect(() => cd.disassemble()).to.not.throw();
});
});
4 changes: 2 additions & 2 deletions libraries/botframework-streaming/tests/ContentStream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Streaming Extensions ContentStream Tests ', function () {
it('does not return the stream when it is is undefined', function () {
const cs = new ContentStream('1', new PayloadAssembler(streamManager, { id: 'csa1', header: header }));

expect(cs.getStream()).to.not.be.undefined;
expect(cs.getStream()).to.not.equal(undefined);
});

it('reads a stream of length 0 and returns an empty string', function () {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Streaming Extensions ContentStream Tests ', function () {
return cs
.readAsJson()
.then((data) => {
expect(data).to.not.be.undefined;
expect(data).to.not.be.undefined();
})
.catch((err) => {
expect(err.toString()).to.equal('SyntaxError: Unexpected end of JSON input');
Expand Down
46 changes: 0 additions & 46 deletions libraries/botframework-streaming/tests/Disassembler.test.js

This file was deleted.

Loading

0 comments on commit 60fed56

Please sign in to comment.