From bb1f78d4e10d00485338a00682be803ae88738fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=BBuraw?= <9116238+krzysztofzuraw@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:33:51 +0200 Subject: [PATCH] Fix couple of eslint rules (#4058) --- .changeset/many-icons-flow.md | 5 +++ .eslintrc.json | 11 +------ .../AppDetailsPage/AppDetailsPage.test.tsx | 1 + src/apps/components/AppFrame/AppIFrame.tsx | 2 ++ .../InstallWithManifestFormButton.tsx | 5 ++- src/components/AppLayout/util.ts | 2 +- src/components/Form/ExitFormDialog.test.tsx | 1 + src/components/IconButton/IconButton.tsx | 2 ++ src/components/Metadata/Metadata.tsx | 2 ++ src/components/SeoForm/SeoForm.tsx | 2 +- .../BackgroundTasksProvider.tsx | 33 +++++++------------ .../PermissionAlert/PermissionAlert.test.tsx | 1 + src/giftCards/index.tsx | 2 +- src/icons/Attributes.tsx | 8 ++--- src/icons/Channels.tsx | 8 ++--- src/icons/Miscellaneous.tsx | 8 ++--- src/icons/Navigation.tsx | 8 ++--- src/icons/PageTypes.tsx | 8 ++--- src/icons/PermissionGroups.tsx | 8 ++--- src/icons/ProductTypes.tsx | 8 ++--- src/icons/ShippingMethods.tsx | 8 ++--- src/icons/SiteSettings.tsx | 8 ++--- src/icons/StaffMembers.tsx | 8 ++--- src/icons/Taxes.tsx | 8 ++--- src/icons/Warehouses.tsx | 8 ++--- src/navigation/views/MenuDetails/index.tsx | 1 - .../components/OrderHistory/messages.ts | 2 ++ .../handlers/multiFileUploadHandler.test.ts | 2 +- 28 files changed, 83 insertions(+), 87 deletions(-) create mode 100644 .changeset/many-icons-flow.md diff --git a/.changeset/many-icons-flow.md b/.changeset/many-icons-flow.md new file mode 100644 index 000000000..a52bb8a5f --- /dev/null +++ b/.changeset/many-icons-flow.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Fix couple of eslint rules connected to display name and no-case declarations diff --git a/.eslintrc.json b/.eslintrc.json index e8d0c30e4..9df011dbe 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -101,16 +101,7 @@ "array-callback-return": "off", "import/export": "off", "n/no-callback-literal": "off", - "no-case-declarations": "off", - "no-empty-pattern": "off", - "no-fallthrough": "off", - "no-new": "off", - "no-prototype-builtins": "off", - "no-unreachable": "off", - "no-useless-catch": "off", - "no-useless-escape": "off", - "prefer-promise-reject-errors": "off", - "react/display-name": "warn" + "no-case-declarations": "warn" }, "ignorePatterns": ["node_modules/", "**/types/**/*", "type-policies.ts"] } diff --git a/src/apps/components/AppDetailsPage/AppDetailsPage.test.tsx b/src/apps/components/AppDetailsPage/AppDetailsPage.test.tsx index 585e3b12d..bfea6ca82 100644 --- a/src/apps/components/AppDetailsPage/AppDetailsPage.test.tsx +++ b/src/apps/components/AppDetailsPage/AppDetailsPage.test.tsx @@ -6,6 +6,7 @@ import { appDetails } from "../../fixtures"; import { AppDetailsPage } from "./AppDetailsPage"; const mockHeader = jest.fn(); +// eslint-disable-next-line react/display-name jest.mock("./Header", () => props => { mockHeader(props); return <>; diff --git a/src/apps/components/AppFrame/AppIFrame.tsx b/src/apps/components/AppFrame/AppIFrame.tsx index 58565e51b..45a3f57e9 100644 --- a/src/apps/components/AppFrame/AppIFrame.tsx +++ b/src/apps/components/AppFrame/AppIFrame.tsx @@ -48,6 +48,8 @@ const _AppIFrame = forwardRef( }, ); +_AppIFrame.displayName = "AppIFrame"; + export const AppIFrame = memo(_AppIFrame, (prev, next) => isEqualWith(prev, next), ); diff --git a/src/apps/components/InstallWithManifestFormButton/InstallWithManifestFormButton.tsx b/src/apps/components/InstallWithManifestFormButton/InstallWithManifestFormButton.tsx index 7caf6cd6e..3a3591144 100644 --- a/src/apps/components/InstallWithManifestFormButton/InstallWithManifestFormButton.tsx +++ b/src/apps/components/InstallWithManifestFormButton/InstallWithManifestFormButton.tsx @@ -27,9 +27,8 @@ export const InstallWithManifestFormButton: React.FC< const inputValue = form.get("manifest-url") as string; try { - new URL(inputValue); - - onSubmitted(inputValue); + const parsedURL = new URL(inputValue); + onSubmitted(parsedURL.href); } catch (e) { console.error("Invalid URL from input. Should be validated by browser"); } diff --git a/src/components/AppLayout/util.ts b/src/components/AppLayout/util.ts index fa392317c..5d11031f0 100644 --- a/src/components/AppLayout/util.ts +++ b/src/components/AppLayout/util.ts @@ -10,7 +10,7 @@ export const extractQueryParams = (queryString: string) => { if (match) { const arrayKey = match[1]; - if (!queryParams.hasOwnProperty(arrayKey)) { + if (!Object.prototype.hasOwnProperty.call(queryParams, arrayKey)) { queryParams[arrayKey] = []; } diff --git a/src/components/Form/ExitFormDialog.test.tsx b/src/components/Form/ExitFormDialog.test.tsx index 3c7edc77a..78cc7e2a8 100644 --- a/src/components/Form/ExitFormDialog.test.tsx +++ b/src/components/Form/ExitFormDialog.test.tsx @@ -14,6 +14,7 @@ jest.mock("react-intl", () => ({ jest.mock("@saleor/macaw-ui", () => ({ useStyles: jest.fn(() => () => ({})), makeStyles: jest.fn(() => () => ({})), + // eslint-disable-next-line react/display-name DialogHeader: jest.fn(() => () => <>), })); diff --git a/src/components/IconButton/IconButton.tsx b/src/components/IconButton/IconButton.tsx index f604222e1..1a84179b8 100644 --- a/src/components/IconButton/IconButton.tsx +++ b/src/components/IconButton/IconButton.tsx @@ -18,6 +18,8 @@ const _IconButton: React.FC = React.forwardRef( }, ); +_IconButton.displayName = "IconButton"; + export const IconButton = _IconButton as < T extends React.ElementType = "button", >( diff --git a/src/components/Metadata/Metadata.tsx b/src/components/Metadata/Metadata.tsx index 309cfe1c8..917b97ab2 100644 --- a/src/components/Metadata/Metadata.tsx +++ b/src/components/Metadata/Metadata.tsx @@ -83,3 +83,5 @@ export const Metadata: React.FC = memo(({ data, onChange }) => { ); }, propsCompare); + +Metadata.displayName = "Metadata"; diff --git a/src/components/SeoForm/SeoForm.tsx b/src/components/SeoForm/SeoForm.tsx index 08ce368a8..bfc793387 100644 --- a/src/components/SeoForm/SeoForm.tsx +++ b/src/components/SeoForm/SeoForm.tsx @@ -20,7 +20,7 @@ enum SeoField { description = "seoDescription", } -const SLUG_REGEX = /^[a-zA-Z0-9\-\_]+$/; +const SLUG_REGEX = /^[a-zA-Z0-9\-_]+$/; const maxSlugLength = 255; const maxTitleLength = 70; const maxDescriptionLength = 300; diff --git a/src/containers/BackgroundTasks/BackgroundTasksProvider.tsx b/src/containers/BackgroundTasks/BackgroundTasksProvider.tsx index de4621e63..2a301e8f1 100644 --- a/src/containers/BackgroundTasks/BackgroundTasksProvider.tsx +++ b/src/containers/BackgroundTasks/BackgroundTasksProvider.tsx @@ -28,29 +28,20 @@ export function useBackgroundTasks( React.useEffect(() => { const intervalId = setInterval(() => { const queue = async () => { - try { - await Promise.all( - tasks.current.map(async task => { - if (task.status === TaskStatus.PENDING) { - let status: TaskStatus; + await Promise.all( + tasks.current.map(async task => { + if (task.status === TaskStatus.PENDING) { + const status = await handleTask(task); - try { - status = await handleTask(task); - } catch (error) { - throw error; - } - if (status !== TaskStatus.PENDING) { - const taskIndex = tasks.current.findIndex( - t => t.id === task.id, - ); - tasks.current[taskIndex].status = status; - } + if (status !== TaskStatus.PENDING) { + const taskIndex = tasks.current.findIndex( + t => t.id === task.id, + ); + tasks.current[taskIndex].status = status; } - }), - ); - } catch (error) { - throw error; - } + } + }), + ); }; queue(); diff --git a/src/custom-apps/components/PermissionAlert/PermissionAlert.test.tsx b/src/custom-apps/components/PermissionAlert/PermissionAlert.test.tsx index 0e8794906..6fe71b6b6 100644 --- a/src/custom-apps/components/PermissionAlert/PermissionAlert.test.tsx +++ b/src/custom-apps/components/PermissionAlert/PermissionAlert.test.tsx @@ -23,6 +23,7 @@ jest.mock("@saleor/macaw-ui", () => ({ useTheme: jest.fn(() => () => ({})), useStyles: jest.fn(() => () => ({})), makeStyles: jest.fn(() => () => ({})), + // eslint-disable-next-line react/display-name DialogHeader: jest.fn(() => () => <>), })); diff --git a/src/giftCards/index.tsx b/src/giftCards/index.tsx index c6c3d7b05..60697f5d8 100644 --- a/src/giftCards/index.tsx +++ b/src/giftCards/index.tsx @@ -41,7 +41,7 @@ const GiftCardList: React.FC> = () => { return ; }; -const Component: React.FC = ({}) => { +const Component: React.FC = () => { const intl = useIntl(); return ( diff --git a/src/icons/Attributes.tsx b/src/icons/Attributes.tsx index 8eac69714..e4e5b0b19 100644 --- a/src/icons/Attributes.tsx +++ b/src/icons/Attributes.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Attributes = createSvgIcon( +const AttributesIcons = createSvgIcon( ( - -); +export default function Attributes(props: SvgIconProps) { + return ; +} diff --git a/src/icons/Channels.tsx b/src/icons/Channels.tsx index a10f45903..fed5c87c0 100644 --- a/src/icons/Channels.tsx +++ b/src/icons/Channels.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Channels = createSvgIcon( +const ChannelsIcon = createSvgIcon( ( - -); +export default function Channels(props: SvgIconProps) { + return ; +} diff --git a/src/icons/Miscellaneous.tsx b/src/icons/Miscellaneous.tsx index 5de53eed3..30768099a 100644 --- a/src/icons/Miscellaneous.tsx +++ b/src/icons/Miscellaneous.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Miscellaneous = createSvgIcon( +const MiscellaneousIcon = createSvgIcon( <> ( - -); +export default function Miscellaneous(props: SvgIconProps) { + return ; +} diff --git a/src/icons/Navigation.tsx b/src/icons/Navigation.tsx index 1aef06245..4f952904f 100644 --- a/src/icons/Navigation.tsx +++ b/src/icons/Navigation.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Navigation = createSvgIcon( +const NavigationIcon = createSvgIcon( ( - -); +export default function Navigation(props: SvgIconProps) { + return ; +} diff --git a/src/icons/PageTypes.tsx b/src/icons/PageTypes.tsx index 36366936a..0e98a3cdd 100644 --- a/src/icons/PageTypes.tsx +++ b/src/icons/PageTypes.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const PageTypes = createSvgIcon( +const PageTypesIcons = createSvgIcon( ( - -); +export default function PageTypes(props: SvgIconProps) { + return ; +} diff --git a/src/icons/PermissionGroups.tsx b/src/icons/PermissionGroups.tsx index 385122762..476962dbf 100644 --- a/src/icons/PermissionGroups.tsx +++ b/src/icons/PermissionGroups.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const PermissionGroups = createSvgIcon( +const PermissionGroupsIcon = createSvgIcon( ( - -); +export default function PermissionGroups(props: SvgIconProps) { + return ; +} diff --git a/src/icons/ProductTypes.tsx b/src/icons/ProductTypes.tsx index 14b71480f..0d832088d 100644 --- a/src/icons/ProductTypes.tsx +++ b/src/icons/ProductTypes.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const ProductTypes = createSvgIcon( +const ProductTypesIcon = createSvgIcon( <> ( - -); +export default function ProductTypes(props: SvgIconProps) { + return ; +} diff --git a/src/icons/ShippingMethods.tsx b/src/icons/ShippingMethods.tsx index 6433d0365..62071f32d 100644 --- a/src/icons/ShippingMethods.tsx +++ b/src/icons/ShippingMethods.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const ShippingMethods = createSvgIcon( +const ShippingMethodsIcons = createSvgIcon( ( - -); +export default function ShippingMethods(props: SvgIconProps) { + return ; +} diff --git a/src/icons/SiteSettings.tsx b/src/icons/SiteSettings.tsx index 8fe880a4f..faec71654 100644 --- a/src/icons/SiteSettings.tsx +++ b/src/icons/SiteSettings.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const SiteSettings = createSvgIcon( +const SiteSettingsIcon = createSvgIcon( <> ( - -); +export default function SiteSettings(props: SvgIconProps) { + return ; +} diff --git a/src/icons/StaffMembers.tsx b/src/icons/StaffMembers.tsx index 111554d55..7d0ef16a3 100644 --- a/src/icons/StaffMembers.tsx +++ b/src/icons/StaffMembers.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const StaffMembers = createSvgIcon( +const StaffMembersIcon = createSvgIcon( ( - -); +export default function StaffMembers(props: SvgIconProps) { + return ; +} diff --git a/src/icons/Taxes.tsx b/src/icons/Taxes.tsx index 99a8df051..a5a864090 100644 --- a/src/icons/Taxes.tsx +++ b/src/icons/Taxes.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Taxes = createSvgIcon( +const TaxesIcon = createSvgIcon( ( - -); +export default function Taxes(props: SvgIconProps) { + return ; +} diff --git a/src/icons/Warehouses.tsx b/src/icons/Warehouses.tsx index c62b2df59..888f4affa 100644 --- a/src/icons/Warehouses.tsx +++ b/src/icons/Warehouses.tsx @@ -1,7 +1,7 @@ import { createSvgIcon, SvgIconProps } from "@material-ui/core"; import React from "react"; -const Warehouses = createSvgIcon( +const WarehousesIcon = createSvgIcon( ( - -); +export default function Warehouses(props: SvgIconProps) { + return ; +} diff --git a/src/navigation/views/MenuDetails/index.tsx b/src/navigation/views/MenuDetails/index.tsx index edd68f32e..45f9222a3 100644 --- a/src/navigation/views/MenuDetails/index.tsx +++ b/src/navigation/views/MenuDetails/index.tsx @@ -119,7 +119,6 @@ const MenuDetails: React.FC = ({ id, params }) => { default: throw unknownTypeError; - break; } }; diff --git a/src/orders/components/OrderHistory/messages.ts b/src/orders/components/OrderHistory/messages.ts index 8748a7747..7564aa883 100644 --- a/src/orders/components/OrderHistory/messages.ts +++ b/src/orders/components/OrderHistory/messages.ts @@ -100,6 +100,8 @@ export const getEventMessage = ( defaultMessage: "Order refund information was sent to customer", description: "order history message", }); + default: + return ""; } case OrderEventsEnum.FULFILLMENT_CANCELED: return intl.formatMessage({ diff --git a/src/utils/handlers/multiFileUploadHandler.test.ts b/src/utils/handlers/multiFileUploadHandler.test.ts index cdbcf1edb..485e685b5 100644 --- a/src/utils/handlers/multiFileUploadHandler.test.ts +++ b/src/utils/handlers/multiFileUploadHandler.test.ts @@ -48,7 +48,7 @@ describe("Multiple file upload handler", () => { const handle = createMultiFileUploadHandler((_, fileIndex) => { const promise = new Promise((resolve, reject) => { if (fileIndex === 2) { - reject(); + reject(new Error("mock error")); } else { resolve(); }