Enabled @typescript-eslint/no-unsafe-call eslint rule again

This commit is contained in:
Alejandro Celaya 2021-02-28 17:43:41 +01:00
parent 86544f4b24
commit 1fe76500e8
7 changed files with 18 additions and 13 deletions

View file

@ -16,9 +16,8 @@
}, },
"rules": { "rules": {
"@typescript-eslint/no-unsafe-assignment": "off", "@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off", "@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/naming-convention": "off", "@typescript-eslint/naming-convention": "off",
"@typescript-eslint/ban-types": "off", "@typescript-eslint/ban-types": "off",

View file

@ -1,5 +1,10 @@
declare module 'event-source-polyfill' { declare module 'event-source-polyfill' {
export const EventSourcePolyfill: any; declare class EventSourcePolyfill {
public onmessage?: ({ data }: { data: string }) => void;
public onerror?: ({ status }: { status: number }) => void;
public close: Function;
public constructor(hubUrl: URL, options?: any);
}
} }
declare module 'csvjson' { declare module 'csvjson' {

View file

@ -20,7 +20,8 @@ type LazyActionMap = Record<string, Function>;
const bottle = new Bottle(); const bottle = new Bottle();
const { container } = bottle; const { container } = bottle;
const lazyService = (container: IContainer, serviceName: string) => (...args: any[]) => container[serviceName](...args); const lazyService = <T extends Function>(container: IContainer, serviceName: string) =>
(...args: any[]) => (container[serviceName] as T)(...args);
const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({ const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({
...map, ...map,
// Wrap actual action service in a function so that it is lazily created the first time it is called // Wrap actual action service in a function so that it is lazily created the first time it is called

View file

@ -11,7 +11,7 @@ export const bindToMercureTopic = <T>(mercureInfo: MercureInfo, topics: string[]
const onEventSourceMessage = ({ data }: { data: string }) => onMessage(JSON.parse(data) as T); const onEventSourceMessage = ({ data }: { data: string }) => onMessage(JSON.parse(data) as T);
const onEventSourceError = ({ status }: { status: number }) => status === 401 && onTokenExpired(); const onEventSourceError = ({ status }: { status: number }) => status === 401 && onTokenExpired();
const subscriptions: EventSource[] = topics.map((topic) => { const subscriptions = topics.map((topic) => {
const hubUrl = new URL(mercureHubUrl); const hubUrl = new URL(mercureHubUrl);
hubUrl.searchParams.append('topic', topic); hubUrl.searchParams.append('topic', topic);

View file

@ -34,7 +34,7 @@ export const useToggle = (initialValue = false): ToggleResult => {
export const useSwipeable = (showSidebar: () => void, hideSidebar: () => void) => { export const useSwipeable = (showSidebar: () => void, hideSidebar: () => void) => {
const swipeMenuIfNoModalExists = (callback: () => void) => (e: any) => { const swipeMenuIfNoModalExists = (callback: () => void) => (e: any) => {
const swippedOnVisitsTable = (e.event.composedPath() as HTMLElement[]).some( // eslint-disable-lin @typescript-eslint/no-unsafe-call const swippedOnVisitsTable = (e.event.composedPath() as HTMLElement[]).some( // eslint-disable-line @typescript-eslint/no-unsafe-call
({ classList }) => classList?.contains('visits-table'), ({ classList }) => classList?.contains('visits-table'),
); );

View file

@ -1,4 +1,4 @@
import { EventSourcePolyfill as EventSource } from 'event-source-polyfill'; import { EventSourcePolyfill } from 'event-source-polyfill';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { identity } from 'ramda'; import { identity } from 'ramda';
import { bindToMercureTopic } from '../../../src/mercure/helpers'; import { bindToMercureTopic } from '../../../src/mercure/helpers';
@ -22,7 +22,7 @@ describe('helpers', () => {
])('does not bind an EventSource when loading, error or no hub URL', (mercureInfo) => { ])('does not bind an EventSource when loading, error or no hub URL', (mercureInfo) => {
bindToMercureTopic(mercureInfo, [ '' ], identity, identity); bindToMercureTopic(mercureInfo, [ '' ], identity, identity);
expect(EventSource).not.toHaveBeenCalled(); expect(EventSourcePolyfill).not.toHaveBeenCalled();
expect(onMessage).not.toHaveBeenCalled(); expect(onMessage).not.toHaveBeenCalled();
expect(onTokenExpired).not.toHaveBeenCalled(); expect(onTokenExpired).not.toHaveBeenCalled();
}); });
@ -42,16 +42,16 @@ describe('helpers', () => {
token, token,
}, [ topic ], onMessage, onTokenExpired); }, [ topic ], onMessage, onTokenExpired);
expect(EventSource).toHaveBeenCalledWith(hubUrl, { expect(EventSourcePolyfill).toHaveBeenCalledWith(hubUrl, {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
}); });
const [ es ] = EventSource.mock.instances; const [ es ] = (EventSourcePolyfill as any).mock.instances as EventSourcePolyfill[];
es.onmessage({ data: '{"foo": "bar"}' }); es.onmessage?.({ data: '{"foo": "bar"}' });
es.onerror({ status: 401 }); es.onerror?.({ status: 401 });
expect(onMessage).toHaveBeenCalledWith({ foo: 'bar' }); expect(onMessage).toHaveBeenCalledWith({ foo: 'bar' });
expect(onTokenExpired).toHaveBeenCalled(); expect(onTokenExpired).toHaveBeenCalled();

View file

@ -60,7 +60,7 @@ describe('<ShortUrlsRowMenu />', () => {
const wrapper = createWrapper(); const wrapper = createWrapper();
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(false); expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(false);
wrapper.find(modalComponent).prop('toggle')(); (wrapper.find(modalComponent).prop('toggle') as Function)();
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(true); expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(true);
}; };