From 7e80c8aa6e776f7f73e663b4cbc3d64d9ab8e6a9 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 6 Jan 2025 12:26:15 +0100 Subject: [PATCH] :rotating_light: [#582] Address linter errors Addressed the linter errors to minimize the impact on the project. Some lines are ignored because they are valid and consistent in the project, but ignoring the rule as a whole would allow other mistakes to fall through/go undetected. --- frontend/.storybook/decorators.tsx | 1 - frontend/.storybook/playFunctions.ts | 4 ++-- frontend/src/App.test.tsx | 1 - .../DestructionListAuditLogDetails.stories.tsx | 2 +- .../DestructionListReviewer.tsx | 4 ++-- .../DestructionListToolbar.tsx | 2 +- .../src/contexts/ZaakSelectionContext.test.tsx | 3 +-- frontend/src/hooks/useCoReviews.ts | 2 +- .../src/hooks/useDestructionListCoReviewers.ts | 2 +- frontend/src/hooks/useZaakSelection.test.ts | 1 - frontend/src/hooks/useZaakSelection.ts | 14 +------------- frontend/src/lib/api/zaakSelection.ts | 2 ++ frontend/src/lib/auth/permissions.test.ts | 2 -- frontend/src/lib/format/date.ts | 1 + .../destructionlist/abstract/BaseListView.tsx | 5 ++++- .../create/DestructionListCreate.stories.tsx | 7 +------ .../detail/DestructionListDetail.tsx | 2 +- .../DestructionListEditPage.tsx | 2 +- .../DestructionListProcessReviewPage.tsx | 2 +- .../review/DestructionListReview.action.ts | 9 ++------- frontend/src/pages/login/Login.tsx | 1 - 21 files changed, 23 insertions(+), 46 deletions(-) diff --git a/frontend/.storybook/decorators.tsx b/frontend/.storybook/decorators.tsx index ad199e91..e3a81ffb 100644 --- a/frontend/.storybook/decorators.tsx +++ b/frontend/.storybook/decorators.tsx @@ -1,5 +1,4 @@ import { StoryContext, StoryFn } from "@storybook/react"; -import * as React from "react"; import { RouterProvider, createBrowserRouter, diff --git a/frontend/.storybook/playFunctions.ts b/frontend/.storybook/playFunctions.ts index 1484b098..1bde8713 100644 --- a/frontend/.storybook/playFunctions.ts +++ b/frontend/.storybook/playFunctions.ts @@ -176,7 +176,6 @@ export const clickCheckbox: PlayFunction = async (context) => { */ export const clickElement: PlayFunction = async (context) => { const { - checked = false, elementIndex = 0, inTBody = false, role, @@ -237,12 +236,13 @@ export const fillForm: PlayFunction = async (context) => { : fields[0]; // Exception if not found. switch (typeof value) { - case "boolean": + case "boolean": { const checkbox = field as HTMLInputElement; if (checkbox.checked !== value) { await userEvent.click(checkbox, { delay: 100 }); } break; + } case "string": if ((field as HTMLSelectElement).options) { const select = field as HTMLSelectElement; diff --git a/frontend/src/App.test.tsx b/frontend/src/App.test.tsx index f1c97c0f..ea28da81 100644 --- a/frontend/src/App.test.tsx +++ b/frontend/src/App.test.tsx @@ -1,5 +1,4 @@ import { render } from "@testing-library/react"; -import * as React from "react"; import { RouterProvider, createBrowserRouter } from "react-router-dom"; import App from "./App"; diff --git a/frontend/src/components/DestructionListAuditLog/DestructionListAuditLogDetails.stories.tsx b/frontend/src/components/DestructionListAuditLog/DestructionListAuditLogDetails.stories.tsx index a9fb29bb..dcd1398d 100644 --- a/frontend/src/components/DestructionListAuditLog/DestructionListAuditLogDetails.stories.tsx +++ b/frontend/src/components/DestructionListAuditLog/DestructionListAuditLogDetails.stories.tsx @@ -45,6 +45,6 @@ export const AuditLogDetails: StoryObj = canvas.getByText("31/12/2021", { exact: false }), ).toBeInTheDocument(); expect(canvas.getByText("This is a comment")).toBeInTheDocument(); - expect(canvas.getByText("10")).toBeInTheDocument; + expect(canvas.getByText("10")).toBeInTheDocument(); }, }; diff --git a/frontend/src/components/DestructionListReviewer/DestructionListReviewer.tsx b/frontend/src/components/DestructionListReviewer/DestructionListReviewer.tsx index 2cd4fe8c..298dbd92 100644 --- a/frontend/src/components/DestructionListReviewer/DestructionListReviewer.tsx +++ b/frontend/src/components/DestructionListReviewer/DestructionListReviewer.tsx @@ -117,7 +117,7 @@ export function DestructionListReviewer({ const data = await e.json(); const errors = collectErrors(data).join("\n"); alert("Foutmelding", data.detail || errors, "Ok"); - } catch (e) { + } catch { alert( "Foutmelding", "Er is een fout opgetreden bij het bewerken van de mede beoordelaars!", @@ -140,7 +140,7 @@ export function DestructionListReviewer({ const data = await e.json(); const errors = collectErrors(data).join("\n"); alert("Foutmelding", data.detail || errors, "Ok"); - } catch (e) { + } catch { alert( "Foutmelding", "Er is een fout opgetreden bij het bewerken van de beoordelaar!", diff --git a/frontend/src/components/DestructionListToolbar/DestructionListToolbar.tsx b/frontend/src/components/DestructionListToolbar/DestructionListToolbar.tsx index c6ac3925..6b8e64d5 100644 --- a/frontend/src/components/DestructionListToolbar/DestructionListToolbar.tsx +++ b/frontend/src/components/DestructionListToolbar/DestructionListToolbar.tsx @@ -149,7 +149,7 @@ export function DestructionListToolbar({ const data = await e.json(); const errors = collectErrors(data).join("\n"); alert("Foutmelding", data.detail || errors, "Ok"); - } catch (e) { + } catch { alert( "Foutmelding", "Er is een fout opgetreden bij het bewerken van de naam van de vernietigingslijst.", diff --git a/frontend/src/contexts/ZaakSelectionContext.test.tsx b/frontend/src/contexts/ZaakSelectionContext.test.tsx index a4a32936..05a02273 100644 --- a/frontend/src/contexts/ZaakSelectionContext.test.tsx +++ b/frontend/src/contexts/ZaakSelectionContext.test.tsx @@ -1,6 +1,5 @@ import { render } from "@testing-library/react"; -import exp from "node:constants"; -import React, { useContext, useEffect, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { DEFAULT_ZAAK_SELECTION_CONTEXT, diff --git a/frontend/src/hooks/useCoReviews.ts b/frontend/src/hooks/useCoReviews.ts index 8f34e9dd..534ed66c 100644 --- a/frontend/src/hooks/useCoReviews.ts +++ b/frontend/src/hooks/useCoReviews.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { CoReview, listCoReviews } from "../lib/api/coReview"; import { DestructionList } from "../lib/api/destructionLists"; diff --git a/frontend/src/hooks/useDestructionListCoReviewers.ts b/frontend/src/hooks/useDestructionListCoReviewers.ts index 0192ac1f..91d49d8c 100644 --- a/frontend/src/hooks/useDestructionListCoReviewers.ts +++ b/frontend/src/hooks/useDestructionListCoReviewers.ts @@ -3,8 +3,8 @@ import { useEffect, useState } from "react"; import { DestructionList, DestructionListAssignee, + listDestructionListCoReviewers, } from "../lib/api/destructionLists"; -import { listDestructionListCoReviewers } from "../lib/api/destructionLists"; import { useAlertOnError } from "./useAlertOnError"; /** diff --git a/frontend/src/hooks/useZaakSelection.test.ts b/frontend/src/hooks/useZaakSelection.test.ts index 7844b14e..9d35ce38 100644 --- a/frontend/src/hooks/useZaakSelection.test.ts +++ b/frontend/src/hooks/useZaakSelection.test.ts @@ -2,7 +2,6 @@ import { act, renderHook, waitFor } from "@testing-library/react"; import { ZaakSelectionContextProvider } from "../contexts"; import { ZaakIdentifier } from "../lib/zaakSelection"; -import { Zaak } from "../types"; import { useZaakSelection } from "./useZaakSelection"; jest.mock("react-router-dom", () => ({ diff --git a/frontend/src/hooks/useZaakSelection.ts b/frontend/src/hooks/useZaakSelection.ts index 0ade1b62..0fe2cf6a 100644 --- a/frontend/src/hooks/useZaakSelection.ts +++ b/frontend/src/hooks/useZaakSelection.ts @@ -232,19 +232,6 @@ export function useZaakSelection( throw error; }; - /** - * Converts selection to string for camparison. - * @param selection - */ - const _serializeSelection = (selection: ZaakSelection): string => { - return Object.entries(selection) - .map(([url, { selected, detail }]) => { - const json = detail ? JSON.stringify(detail) : ""; - return `${url}${selected}${json}`; - }) - .join(); - }; - /** * @param size * @private @@ -315,6 +302,7 @@ export function useZaakSelection( ? await Promise.all(detailPromises) : undefined; + // eslint-disable-next-line @typescript-eslint/no-unused-expressions selected ? await addToZaakSelection( storageKey, diff --git a/frontend/src/lib/api/zaakSelection.ts b/frontend/src/lib/api/zaakSelection.ts index 719bacdd..a6c5ea57 100644 --- a/frontend/src/lib/api/zaakSelection.ts +++ b/frontend/src/lib/api/zaakSelection.ts @@ -12,6 +12,7 @@ export async function getSelection( signal?: AbortSignal, ) { const params = new URLSearchParams(exp as Record); + // eslint-disable-next-line @typescript-eslint/no-unused-expressions selectedOnly && params.set("selected", "true"); const response = await request( @@ -37,6 +38,7 @@ export async function getSelectionItems( ) { const items = zaken.map((zaak) => _getZaakUrl(zaak)); const params = new URLSearchParams(); + // eslint-disable-next-line @typescript-eslint/no-unused-expressions selectedOnly && params.set("selected", "true"); const response = await request( "POST", diff --git a/frontend/src/lib/auth/permissions.test.ts b/frontend/src/lib/auth/permissions.test.ts index 15ca1629..efd2e229 100644 --- a/frontend/src/lib/auth/permissions.test.ts +++ b/frontend/src/lib/auth/permissions.test.ts @@ -284,13 +284,11 @@ DESTRUCTION_LIST_STATUSES.forEach((status) => { describe(`canUpdateDestructionList() with destruction list status: ${status}`, () => { let destructionList: DestructionList; let user: User; - let anotherUser: User; beforeEach(() => { user = userFactory({ role: { canStartDestruction: true, canReviewDestruction: true }, }); - anotherUser = { ...user, pk: 2 }; destructionList = destructionListFactory({ status, assignee: user, diff --git a/frontend/src/lib/format/date.ts b/frontend/src/lib/format/date.ts index 460e20cf..7ac730d1 100644 --- a/frontend/src/lib/format/date.ts +++ b/frontend/src/lib/format/date.ts @@ -106,6 +106,7 @@ export function timeAgo( result = `over ${intervalCount}${shortFormat ? "" : " "}${label}`; } else { // Special case to not include "geleden" for the short format + // eslint-disable-next-line max-depth if (shortFormat) { result = `${intervalCount}${shortFormat ? "" : " "}${label}`; } else { diff --git a/frontend/src/pages/destructionlist/abstract/BaseListView.tsx b/frontend/src/pages/destructionlist/abstract/BaseListView.tsx index 950417e8..e2b6c09b 100644 --- a/frontend/src/pages/destructionlist/abstract/BaseListView.tsx +++ b/frontend/src/pages/destructionlist/abstract/BaseListView.tsx @@ -14,9 +14,12 @@ import { DestructionListToolbar } from "../../../components"; import { ZaakSelectionDetailGetter, ZaakSelectionZaakFilter, + useFields, + useFilter, + usePage, + useSort, useZaakSelection, } from "../../../hooks"; -import { useFields, useFilter, usePage, useSort } from "../../../hooks"; import { DestructionList } from "../../../lib/api/destructionLists"; import { Review } from "../../../lib/api/review"; import { PaginatedZaken } from "../../../lib/api/zaken"; diff --git a/frontend/src/pages/destructionlist/create/DestructionListCreate.stories.tsx b/frontend/src/pages/destructionlist/create/DestructionListCreate.stories.tsx index cfa69771..21c17bac 100644 --- a/frontend/src/pages/destructionlist/create/DestructionListCreate.stories.tsx +++ b/frontend/src/pages/destructionlist/create/DestructionListCreate.stories.tsx @@ -1,5 +1,4 @@ import type { Meta, StoryObj } from "@storybook/react"; -import { userEvent, within } from "@storybook/test"; import { ClearSessionStorageDecorator, @@ -12,11 +11,7 @@ import { fillForm, } from "../../../../.storybook/playFunctions"; import { paginatedZakenFactory } from "../../../fixtures/paginatedZaken"; -import { - beoordelaarFactory, - recordManagerFactory, - usersFactory, -} from "../../../fixtures/user"; +import { usersFactory } from "../../../fixtures/user"; import { getZaakSelection } from "../../../lib/zaakSelection"; import { DESTRUCTION_LIST_CREATE_KEY, diff --git a/frontend/src/pages/destructionlist/detail/DestructionListDetail.tsx b/frontend/src/pages/destructionlist/detail/DestructionListDetail.tsx index 3795d297..c69044f6 100644 --- a/frontend/src/pages/destructionlist/detail/DestructionListDetail.tsx +++ b/frontend/src/pages/destructionlist/detail/DestructionListDetail.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import { useEffect } from "react"; import { Outlet, useLoaderData, diff --git a/frontend/src/pages/destructionlist/detail/pages/DestructionListEditPage/DestructionListEditPage.tsx b/frontend/src/pages/destructionlist/detail/pages/DestructionListEditPage/DestructionListEditPage.tsx index 7cb80b92..fcb8f39a 100644 --- a/frontend/src/pages/destructionlist/detail/pages/DestructionListEditPage/DestructionListEditPage.tsx +++ b/frontend/src/pages/destructionlist/detail/pages/DestructionListEditPage/DestructionListEditPage.tsx @@ -1,5 +1,5 @@ import { ButtonProps, Solid, TypedField } from "@maykin-ui/admin-ui"; -import React, { useMemo } from "react"; +import { useMemo } from "react"; import { useNavigation, useRouteLoaderData, diff --git a/frontend/src/pages/destructionlist/detail/pages/DestructionListProcessReviewPage/DestructionListProcessReviewPage.tsx b/frontend/src/pages/destructionlist/detail/pages/DestructionListProcessReviewPage/DestructionListProcessReviewPage.tsx index f76ffce8..4c249d45 100644 --- a/frontend/src/pages/destructionlist/detail/pages/DestructionListProcessReviewPage/DestructionListProcessReviewPage.tsx +++ b/frontend/src/pages/destructionlist/detail/pages/DestructionListProcessReviewPage/DestructionListProcessReviewPage.tsx @@ -1,5 +1,5 @@ import { Outline, Toolbar, TypedField } from "@maykin-ui/admin-ui"; -import React, { useMemo, useState } from "react"; +import { useMemo, useState } from "react"; import { useRevalidator, useRouteLoaderData } from "react-router-dom"; import { useZaakReviewStatuses, useZaakSelection } from "../../../../../hooks"; diff --git a/frontend/src/pages/destructionlist/review/DestructionListReview.action.ts b/frontend/src/pages/destructionlist/review/DestructionListReview.action.ts index a180c081..5d0c45a3 100644 --- a/frontend/src/pages/destructionlist/review/DestructionListReview.action.ts +++ b/frontend/src/pages/destructionlist/review/DestructionListReview.action.ts @@ -1,18 +1,13 @@ import { ActionFunctionArgs, redirect } from "react-router-dom"; import { TypedAction } from "../../../hooks"; -import { - CoReview, - CoReviewBase, - createCoReview, -} from "../../../lib/api/coReview"; +import { CoReviewBase, createCoReview } from "../../../lib/api/coReview"; import { Review, ZaakReview, createDestructionListReview, } from "../../../lib/api/review"; -import { RestBackend } from "../../../lib/zaakSelection"; -import { clearZaakSelection } from "../../../lib/zaakSelection"; +import { RestBackend, clearZaakSelection } from "../../../lib/zaakSelection"; import { getDestructionListReviewKey } from "./DestructionListReview"; export type DestructionListReviewActionContext = { diff --git a/frontend/src/pages/login/Login.tsx b/frontend/src/pages/login/Login.tsx index abf748de..f2961480 100644 --- a/frontend/src/pages/login/Login.tsx +++ b/frontend/src/pages/login/Login.tsx @@ -1,5 +1,4 @@ import { - FormProps, LoginTemplate, LoginTemplateProps, forceArray,