diff --git a/src/common/AppUpdateBanner.tsx b/src/common/AppUpdateBanner.tsx index 9e58e575..c3c6db62 100644 --- a/src/common/AppUpdateBanner.tsx +++ b/src/common/AppUpdateBanner.tsx @@ -9,7 +9,7 @@ import './AppUpdateBanner.scss'; interface AppUpdateBannerProps { isOpen: boolean; toggle: MouseEventHandler; - forceUpdate: Function; + forceUpdate: () => void; } export const AppUpdateBanner = forwardRef(({ isOpen, toggle, forceUpdate }, ref) => { diff --git a/src/common/Home.tsx b/src/common/Home.tsx index 3388574e..42dc695d 100644 --- a/src/common/Home.tsx +++ b/src/common/Home.tsx @@ -21,7 +21,9 @@ export const Home = ({ servers }: HomeProps) => { useEffect(() => { // Try to redirect to the first server marked as auto-connect const autoConnectServer = serversList.find(({ autoConnect }) => autoConnect); - autoConnectServer && navigate(`/server/${autoConnectServer.id}`); + if (autoConnectServer) { + navigate(`/server/${autoConnectServer.id}`); + } }, [serversList, navigate]); return ( diff --git a/src/common/MainHeader.tsx b/src/common/MainHeader.tsx index 9c879050..34ec76ff 100644 --- a/src/common/MainHeader.tsx +++ b/src/common/MainHeader.tsx @@ -15,7 +15,7 @@ type MainHeaderDeps = { ServersDropdown: FC; }; -const MainHeader: FCWithDeps<{}, MainHeaderDeps> = () => { +const MainHeader: FCWithDeps = () => { const { ServersDropdown } = useDependencies(MainHeader); const [isNotCollapsed, toggleCollapse, , collapse] = useToggle(); const location = useLocation(); diff --git a/src/container/index.ts b/src/container/index.ts index 75648877..4c5e6cb2 100644 --- a/src/container/index.ts +++ b/src/container/index.ts @@ -9,13 +9,13 @@ import { provideServices as provideSettingsServices } from '../settings/services import { provideServices as provideUtilsServices } from '../utils/services/provideServices'; import type { ConnectDecorator } from './types'; -type LazyActionMap = Record; +type LazyActionMap = Record unknown>; const bottle = new Bottle(); export const { container } = bottle; -const lazyService = (cont: IContainer, serviceName: string) => +const lazyService = unknown, K>(cont: IContainer, serviceName: string) => (...args: any[]) => (cont[serviceName] as T)(...args) as K; const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({ diff --git a/src/servers/CreateServer.tsx b/src/servers/CreateServer.tsx index 5e66de55..4fca8a9d 100644 --- a/src/servers/CreateServer.tsx +++ b/src/servers/CreateServer.tsx @@ -60,7 +60,11 @@ const CreateServer: FCWithDeps = ({ servers ({ url, apiKey }) => serverData?.url === url && serverData?.apiKey === apiKey, ); - serverExists ? toggleConfirmModal() : saveNewServer(serverData); + if (serverExists) { + toggleConfirmModal(); + } else { + saveNewServer(serverData); + } }, [saveNewServer, serverData, servers, toggleConfirmModal]); return ( diff --git a/src/servers/DeleteServerModal.tsx b/src/servers/DeleteServerModal.tsx index e7bff9b3..ea7f07c9 100644 --- a/src/servers/DeleteServerModal.tsx +++ b/src/servers/DeleteServerModal.tsx @@ -30,7 +30,9 @@ export const DeleteServerModal: FC = ( } deleteServer(server); - redirectHome && navigate('/'); + if (redirectHome) { + navigate('/'); + } }; return ( diff --git a/src/servers/EditServer.tsx b/src/servers/EditServer.tsx index 87524883..2682e650 100644 --- a/src/servers/EditServer.tsx +++ b/src/servers/EditServer.tsx @@ -31,7 +31,9 @@ const EditServer: FCWithDeps = withSelectedServ const handleSubmit = (serverData: ServerData) => { editServer(selectedServer.id, serverData); - reconnect === 'true' && selectServer(selectedServer.id); + if (reconnect === 'true') { + selectServer(selectedServer.id); + } goBack(); }; diff --git a/src/servers/helpers/ImportServersBtn.tsx b/src/servers/helpers/ImportServersBtn.tsx index 3c5f8b8f..cfc860ed 100644 --- a/src/servers/helpers/ImportServersBtn.tsx +++ b/src/servers/helpers/ImportServersBtn.tsx @@ -58,8 +58,12 @@ const ImportServersBtn: FCWithDeps serversInclude(existingServers, server)); const hasDuplicatedServers = !!dupServers.length; - !hasDuplicatedServers ? create(newServers) : setDuplicatedServers(dupServers); - hasDuplicatedServers && showModal(); + if (!hasDuplicatedServers) { + create(newServers); + } else { + setDuplicatedServers(dupServers); + showModal(); + } }) .then(() => { // Reset input after processing file diff --git a/src/servers/helpers/ServerForm.tsx b/src/servers/helpers/ServerForm.tsx index dc2b63df..eb76dec0 100644 --- a/src/servers/helpers/ServerForm.tsx +++ b/src/servers/helpers/ServerForm.tsx @@ -17,9 +17,11 @@ export const ServerForm: FC = ({ onSubmit, initialValues, child const handleSubmit = handleEventPreventingDefault(() => onSubmit({ name, url, apiKey })); useEffect(() => { - initialValues && setName(initialValues.name); - initialValues && setUrl(initialValues.url); - initialValues && setApiKey(initialValues.apiKey); + if (initialValues) { + setName(initialValues.name); + setUrl(initialValues.url); + setApiKey(initialValues.apiKey); + } }, [initialValues]); return ( diff --git a/src/servers/helpers/withSelectedServer.tsx b/src/servers/helpers/withSelectedServer.tsx index a2158f3a..6e7b087c 100644 --- a/src/servers/helpers/withSelectedServer.tsx +++ b/src/servers/helpers/withSelectedServer.tsx @@ -17,7 +17,7 @@ type WithSelectedServerPropsDeps = { ServerError: FC; }; -export function withSelectedServer( +export function withSelectedServer( WrappedComponent: FCWithDeps, ) { const ComponentWrapper: FCWithDeps = (props) => { @@ -26,7 +26,9 @@ export function withSelectedServer( const { selectServer, selectedServer } = props; useEffect(() => { - params.serverId && selectServer(params.serverId); + if (params.serverId) { + selectServer(params.serverId); + } }, [params.serverId, selectServer]); if (!selectedServer) { diff --git a/src/servers/helpers/withoutSelectedServer.tsx b/src/servers/helpers/withoutSelectedServer.tsx index 1c12adb7..5f533dc0 100644 --- a/src/servers/helpers/withoutSelectedServer.tsx +++ b/src/servers/helpers/withoutSelectedServer.tsx @@ -2,10 +2,10 @@ import type { FC } from 'react'; import { useEffect } from 'react'; interface WithoutSelectedServerProps { - resetSelectedServer: Function; + resetSelectedServer: () => unknown; } -export function withoutSelectedServer(WrappedComponent: FC) { +export function withoutSelectedServer(WrappedComponent: FC) { return (props: WithoutSelectedServerProps & T) => { const { resetSelectedServer } = props; useEffect(() => { diff --git a/src/servers/reducers/selectedServer.ts b/src/servers/reducers/selectedServer.ts index 17d50429..512ddb4d 100644 --- a/src/servers/reducers/selectedServer.ts +++ b/src/servers/reducers/selectedServer.ts @@ -50,7 +50,7 @@ export const selectServer = (buildShlinkApiClient: ShlinkApiClientBuilder) => cr version, printableVersion, }; - } catch (e) { + } catch { return { ...selectedServer, serverNotReachable: true }; } }, diff --git a/src/settings/helpers/index.ts b/src/settings/helpers/index.ts index de01ff55..efd57fca 100644 --- a/src/settings/helpers/index.ts +++ b/src/settings/helpers/index.ts @@ -7,8 +7,8 @@ export const migrateDeprecatedSettings = (state: Partial): Partial< } // The "last180Days" interval had a typo, with a lowercase d - if ((state.settings.visits?.defaultInterval as any) === 'last180days') { - state.settings.visits && (state.settings.visits.defaultInterval = 'last180Days'); + if (state.settings.visits && (state.settings.visits.defaultInterval as any) === 'last180days') { + state.settings.visits.defaultInterval = 'last180Days'; } return state; diff --git a/src/utils/helpers/version.ts b/src/utils/helpers/version.ts index 3c27cc9f..0e3ad1bc 100644 --- a/src/utils/helpers/version.ts +++ b/src/utils/helpers/version.ts @@ -38,7 +38,7 @@ export const versionMatch = (versionToMatch: SemVer | Empty, { maxVersion, minVe const versionIsValidSemVer = memoizeWith((v) => v, (version: string): version is SemVer => { try { return compare(version, version, '='); - } catch (e) { + } catch { return false; } }); diff --git a/test/servers/DeleteServerButton.test.tsx b/test/servers/DeleteServerButton.test.tsx index e67217bc..75693268 100644 --- a/test/servers/DeleteServerButton.test.tsx +++ b/test/servers/DeleteServerButton.test.tsx @@ -32,7 +32,9 @@ describe('', () => { expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Closed/); expect(screen.getByText(/DeleteServerModal/)).not.toHaveTextContent(/Open/); - container.firstElementChild && await user.click(container.firstElementChild); + if (container.firstElementChild) { + await user.click(container.firstElementChild); + } await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/)); }); diff --git a/test/servers/helpers/ImportServersBtn.test.tsx b/test/servers/helpers/ImportServersBtn.test.tsx index b2ef75d0..b3ba60c5 100644 --- a/test/servers/helpers/ImportServersBtn.test.tsx +++ b/test/servers/helpers/ImportServersBtn.test.tsx @@ -57,7 +57,9 @@ describe('', () => { const { container } = setUp(); const input = container.querySelector('[type=file]'); - input && fireEvent.change(input, { target: { files: [''] } }); + if (input) { + fireEvent.change(input, { target: { files: [''] } }); + } expect(importServersFromFile).toHaveBeenCalledTimes(1); await waitFor(() => expect(createServersMock).toHaveBeenCalledTimes(1)); }); @@ -73,7 +75,9 @@ describe('', () => { importServersFromFile.mockResolvedValue([existingServer, newServer]); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); - input && fireEvent.change(input, { target: { files: [''] } }); + if (input) { + fireEvent.change(input, { target: { files: [''] } }); + } await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument()); await user.click(screen.getByRole('button', { name: btnName }));