Skip to content

Commit a151817

Browse files
committed
fix: enabling eslint ban-types rule and fixed string typing
1 parent 6f8e7e3 commit a151817

22 files changed

Lines changed: 41 additions & 32 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module.exports = {
3737
],
3838
'@typescript-eslint/no-explicit-any': 'off',
3939
'@typescript-eslint/ban-ts-comment': 'off',
40-
'@typescript-eslint/ban-types': 'off',
4140
'@typescript-eslint/no-var-requires': 'off',
4241
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
4342
'@typescript-eslint/no-this-alias': 'off',

packages/sdk/browser/src/BrowserClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ class BrowserClientImpl extends LDClientImpl {
279279
this.dataManager.setAutomaticStreamingState?.(hasListeners);
280280
}
281281

282-
override on(eventName: LDEmitterEventName, listener: Function): void {
282+
override on(eventName: LDEmitterEventName, listener: (...args: any[]) => void): void {
283283
super.on(eventName, listener);
284284
this._updateAutomaticStreamingState();
285285
}
286286

287-
override off(eventName: LDEmitterEventName, listener: Function): void {
287+
override off(eventName: LDEmitterEventName, listener: (...args: any[]) => void): void {
288288
super.off(eventName, listener);
289289
this._updateAutomaticStreamingState();
290290
}

packages/sdk/electron/__tests__/ElectronClient.ipcMain.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ import ElectronInfo from '../src/platform/ElectronInfo';
1616
import { createMockLogger } from './testHelpers';
1717

1818
type MockIpcMain = IpcMain & {
19-
getHandler: (eventName: string) => Function | undefined;
19+
getHandler: (eventName: string) => ((...args: any[]) => void) | undefined;
2020
removeAllListeners: (channel: string) => void;
2121
removeHandler: (channel: string) => void;
2222
};
23-
type MockPort = { postMessage: Function; close: Function };
23+
type MockPort = { postMessage: (...args: any[]) => void; close: (...args: any[]) => void };
2424
type MockIpcEvent = { returnValue?: any; ports?: MockPort[] };
2525

2626
jest.mock('electron', () => {
27-
const handlers = new Map<string, Function>();
27+
const handlers = new Map<string, (...args: any[]) => void>();
2828
return {
2929
ipcMain: {
30-
on: (eventName: string, handler: Function) => handlers.set(eventName, handler),
31-
handle: (eventName: string, handler: Function) => handlers.set(eventName, handler),
30+
on: (eventName: string, handler: (...args: any[]) => void) =>
31+
handlers.set(eventName, handler),
32+
handle: (eventName: string, handler: (...args: any[]) => void) =>
33+
handlers.set(eventName, handler),
3234
getHandler: (eventName: string) => handlers.get(eventName),
3335
removeAllListeners: (channel: string) => handlers.delete(channel),
3436
removeHandler: (channel: string) => handlers.delete(channel),

packages/sdk/electron/__tests__/ElectronClient.mainProcess.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,19 @@ function createMockEventSourceThatDeliversPut(putData: object) {
5656
});
5757
}
5858

59-
const handlers = new Map<string, Function>();
60-
const mockOn = jest.fn((eventName: string, handler: Function) => {
59+
const handlers = new Map<string, (...args: any[]) => void>();
60+
const mockOn = jest.fn((eventName: string, handler: (...args: any[]) => void) => {
6161
handlers.set(eventName, handler);
6262
});
63-
const mockHandle = jest.fn((eventName: string, handler: Function) => {
63+
const mockHandle = jest.fn((eventName: string, handler: (...args: any[]) => void) => {
6464
handlers.set(eventName, handler);
6565
});
6666

6767
jest.mock('electron', () => ({
6868
ipcMain: {
69-
on: (eventName: string, handler: Function) => mockOn(eventName, handler),
70-
handle: (eventName: string, handler: Function) => mockHandle(eventName, handler),
69+
on: (eventName: string, handler: (...args: any[]) => void) => mockOn(eventName, handler),
70+
handle: (eventName: string, handler: (...args: any[]) => void) =>
71+
mockHandle(eventName, handler),
7172
getHandler: (eventName: string) => handlers.get(eventName),
7273
removeAllListeners: (channel: string) => handlers.delete(channel),
7374
removeHandler: (channel: string) => handlers.delete(channel),

packages/sdk/electron/__tests__/renderer/ElectronRendererClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('given an instance of ElectronRendererClient', () => {
217217
const clientForSyncClose = new ElectronRendererClient(clientSideId);
218218
const syncCloseId = 'sync-close-id';
219219
(ldClientBridge.addEventHandler as jest.Mock).mockImplementation(
220-
(_eventName: string, _cb: Function, onClose?: () => void) => {
220+
(_eventName: string, _cb: (...args: any[]) => void, onClose?: () => void) => {
221221
onClose?.();
222222
return syncCloseId;
223223
},

packages/sdk/electron/src/platform/ElectronRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default class ElectronRequests implements platform.Requests {
122122
const impl = isSecure ? https : http;
123123

124124
const headers = { ...options.headers };
125-
let bodyData: String | Buffer | undefined = options.body;
125+
let bodyData: string | Buffer | undefined = options.body;
126126

127127
// For get requests we are going to automatically support compressed responses.
128128
// Note this does not affect SSE as the event source is not using this fetch implementation.

packages/sdk/server-node/src/Emits.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EventEmitter } from 'events';
22

3+
// eslint-disable-next-line @typescript-eslint/ban-types
34
export type EventableConstructor<T = {}> = new (...args: any[]) => T;
45
export type Eventable = EventableConstructor<{ emitter: EventEmitter }>;
56

@@ -50,10 +51,12 @@ export function Emits<TBase extends Eventable>(Base: TBase) {
5051
return this.emitter.getMaxListeners();
5152
}
5253

54+
// eslint-disable-next-line @typescript-eslint/ban-types
5355
listeners(eventName: string | symbol): Function[] {
5456
return this.emitter.listeners(eventName);
5557
}
5658

59+
// eslint-disable-next-line @typescript-eslint/ban-types
5760
rawListeners(eventName: string | symbol): Function[] {
5861
return this.emitter.rawListeners(eventName);
5962
}

packages/sdk/server-node/src/LDClientNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ class LDClientNode extends LDClientImpl implements LDClient {
133133
return this.emitter.getMaxListeners();
134134
}
135135

136+
// eslint-disable-next-line @typescript-eslint/ban-types
136137
listeners(eventName: string | symbol): Function[] {
137138
return this.emitter.listeners(eventName);
138139
}
139140

141+
// eslint-disable-next-line @typescript-eslint/ban-types
140142
rawListeners(eventName: string | symbol): Function[] {
141143
return this.emitter.rawListeners(eventName);
142144
}

packages/sdk/server-node/src/platform/NodeRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class NodeRequests implements platform.Requests {
126126
const impl = isSecure ? https : http;
127127

128128
const headers = { ...options.headers };
129-
let bodyData: String | Buffer | undefined = options.body;
129+
let bodyData: string | Buffer | undefined = options.body;
130130

131131
// For get requests we are going to automatically support compressed responses.
132132
// Note this does not affect SSE as the event source is not using this fetch implementation.

packages/sdk/shopify-oxygen/contract-tests/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const port = 8000;
1919
const clientPool = new ClientPool();
2020

2121
if (debugging) {
22-
app.use((req: Request, res: Response, next: Function) => {
22+
app.use((req: Request, res: Response, next: (...args: any[]) => void) => {
2323
console.debug('request', req.method, req.url);
2424
if (req.body) {
2525
console.debug('request', JSON.stringify(req.body, null, 2));

0 commit comments

Comments
 (0)