From 951dc93b77c4931c93f7d8ff4ba46814666d64ad Mon Sep 17 00:00:00 2001 From: Sven Kirschbaum Date: Sun, 23 Jun 2024 02:40:11 +0200 Subject: [PATCH] fix: Fix eslint errors --- example/src/App.test.jsx | 1 + example/src/Components.test.jsx | 1 + src/components/StompSessionProvider.tsx | 3 ++- src/hoc/withStompClient.tsx | 6 +++++- src/hoc/withSubscription.tsx | 8 ++++++-- src/interfaces/StompMessageReceiver.ts | 4 ++-- src/interfaces/StompSessionProviderProps.ts | 5 +++-- src/mock/StompSessionProviderMock.tsx | 4 ++-- src/mock/client.tsx | 2 +- src/mock/subscriptions.tsx | 14 +++++++------- 10 files changed, 30 insertions(+), 18 deletions(-) diff --git a/example/src/App.test.jsx b/example/src/App.test.jsx index 0df7207..6ee3484 100644 --- a/example/src/App.test.jsx +++ b/example/src/App.test.jsx @@ -12,6 +12,7 @@ vi.mock('react-stomp-hooks', async () => { }; }) +// eslint-disable-next-line vitest/expect-expect it('app renders without crashing', () => { render(); }) diff --git a/example/src/Components.test.jsx b/example/src/Components.test.jsx index f24d650..f87a00a 100644 --- a/example/src/Components.test.jsx +++ b/example/src/Components.test.jsx @@ -9,6 +9,7 @@ afterEach(() => { //Test Subscribing Component using provided Mock implementation +// eslint-disable-next-line vitest/expect-expect it('Subscribing component works', () => { //Render Subscribing Component, with StompSessionProviderMock render( diff --git a/src/components/StompSessionProvider.tsx b/src/components/StompSessionProvider.tsx index 781a3d2..0a1ad8c 100644 --- a/src/components/StompSessionProvider.tsx +++ b/src/components/StompSessionProvider.tsx @@ -20,7 +20,8 @@ import { StompSessionSubscription } from '../interfaces/StompSessionSubscription * Please consult the @stomp/stompjs documentation for more information. */ function StompSessionProvider(props: StompSessionProviderProps) { - let { url, children, stompClientOptions, ...stompOptions } = props; + const { url, children, stompClientOptions, ...otherProps } = props; + let stompOptions = otherProps; // Support old API if (stompClientOptions) stompOptions = stompClientOptions; diff --git a/src/hoc/withStompClient.tsx b/src/hoc/withStompClient.tsx index c2f9f84..e5b8fbe 100644 --- a/src/hoc/withStompClient.tsx +++ b/src/hoc/withStompClient.tsx @@ -2,10 +2,14 @@ import React from 'react'; import useStompClient from '../hooks/useStompClient'; function withStompClient

(WrappedComponent: React.ComponentType

) { - return (props: P) => { + const comp = (props: P) => { const stompClient = useStompClient(); return ; }; + + comp.displayName = `withStompClient(${WrappedComponent.displayName || WrappedComponent.name})`; + + return comp; } export default withStompClient; diff --git a/src/hoc/withSubscription.tsx b/src/hoc/withSubscription.tsx index f404ad2..129d8c4 100644 --- a/src/hoc/withSubscription.tsx +++ b/src/hoc/withSubscription.tsx @@ -11,7 +11,7 @@ function withSubscription

( destinations: string | string[], headers: StompHeaders = {} ) { - return (props: P) => { + const comp = (props: P) => { const ref = useRef(); useSubscription( destinations, @@ -21,9 +21,13 @@ function withSubscription

( headers ); - // @ts-ignore + // @ts-expect-error - Ref type incompatible return ; }; + + comp.displayName = `withSubscription(${WrappedComponent.displayName || WrappedComponent.name})`; + + return comp; } export default withSubscription; diff --git a/src/interfaces/StompMessageReceiver.ts b/src/interfaces/StompMessageReceiver.ts index 32c2d5e..80ae8ba 100644 --- a/src/interfaces/StompMessageReceiver.ts +++ b/src/interfaces/StompMessageReceiver.ts @@ -5,6 +5,6 @@ export interface MessageReceiverInterface { onMessage: messageCallbackType; } -export type StompMessageReceiver

= React.ComponentClass

& { - new (props: P, context?: any): React.Component

& MessageReceiverInterface; +export type StompMessageReceiver

= React.ComponentClass

& { + new (props: P, context?: unknown): React.Component

& MessageReceiverInterface; }; diff --git a/src/interfaces/StompSessionProviderProps.ts b/src/interfaces/StompSessionProviderProps.ts index 8860237..c22eb22 100644 --- a/src/interfaces/StompSessionProviderProps.ts +++ b/src/interfaces/StompSessionProviderProps.ts @@ -1,10 +1,11 @@ import { StompConfig } from '@stomp/stompjs'; +import { ReactNode } from 'react'; export interface StompSessionProviderProps extends StompConfig { url: string; - children: any; + children: ReactNode; /** * @deprecated */ - stompClientOptions?: any; + stompClientOptions?: object; } diff --git a/src/mock/StompSessionProviderMock.tsx b/src/mock/StompSessionProviderMock.tsx index 541734c..62a2f13 100644 --- a/src/mock/StompSessionProviderMock.tsx +++ b/src/mock/StompSessionProviderMock.tsx @@ -15,13 +15,13 @@ import { getMockClient } from './client'; */ export default function StompSessionProviderMock(props: { children: React.ReactNode; - client?: any; + client?: unknown; }) { return ( diff --git a/src/mock/client.tsx b/src/mock/client.tsx index d1b1984..b5655a5 100644 --- a/src/mock/client.tsx +++ b/src/mock/client.tsx @@ -12,7 +12,7 @@ export function mockClientPublish(params: IPublishParams) { messages.set(params.destination, []); } - // @ts-ignore + // @ts-expect-error - possible undefined messages.get(params.destination).push(params); } diff --git a/src/mock/subscriptions.tsx b/src/mock/subscriptions.tsx index c59a30e..217f305 100644 --- a/src/mock/subscriptions.tsx +++ b/src/mock/subscriptions.tsx @@ -1,26 +1,26 @@ import { IMessage } from '@stomp/stompjs'; import { messageCallbackType, StompHeaders } from '@stomp/stompjs'; -export const subscriptions = new Map>(); +export const subscriptions = new Map>(); export function subscribeMock( destination: string, callback: messageCallbackType, - // @ts-ignore + // @ts-expect-error - irrelevant in mock // eslint-disable-next-line @typescript-eslint/no-unused-vars headers: StompHeaders = {} ) { const subscriptionId = Math.random().toString(36).substr(2, 9); if (!subscriptions.has(destination)) { - subscriptions.set(destination, new Map()); + subscriptions.set(destination, new Map()); } - // @ts-ignore + // @ts-expect-error undefined check subscriptions.get(destination).set(subscriptionId, callback); return () => { - // @ts-ignore + // @ts-expect-error undefined check subscriptions.get(destination).delete(subscriptionId); }; } @@ -35,8 +35,8 @@ export function mockReceiveMessage( message: IMessage ): void { if (subscriptions.has(destination)) { - // @ts-ignore - subscriptions.get(destination).forEach((callback: Function) => { + // @ts-expect-error undefined check + subscriptions.get(destination).forEach((callback: messageCallbackType) => { callback(message); }); }