From 8556c07378445fe205725747a6fa0da68f85f5fb Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Nov 2024 16:56:06 +0100 Subject: [PATCH 1/2] install lint no-catch-all rule --- .eslintrc.js | 4 ++-- package-lock.json | 11 +++++++++++ package.json | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ad8b6e75..3c1e763b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,7 +25,7 @@ module.exports = { 'import', // 'promise', // 'security', - // 'no-catch-all', + 'no-catch-all', 'react', 'react-hooks', ], @@ -44,7 +44,7 @@ module.exports = { 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks 'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies 'react/react-in-jsx-scope': 'off', // Disable requirement for React import - // 'no-catch-all/no-catch-all': 'error', + 'no-catch-all/no-catch-all': 'error', 'no-console': 'error', 'no-debugger': 'error', camelcase: 'error', diff --git a/package-lock.json b/package-lock.json index 74187848..da7b17b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "eslint-plugin-json": "^3.1.0", + "eslint-plugin-no-catch-all": "^1.1.0", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", @@ -2371,6 +2372,16 @@ "node": ">=10" } }, + "node_modules/eslint-plugin-no-catch-all": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-catch-all/-/eslint-plugin-no-catch-all-1.1.0.tgz", + "integrity": "sha512-VkP62jLTmccPrFGN/W6V7a3SEwdtTZm+Su2k4T3uyJirtkm0OMMm97h7qd8pRFAHus/jQg9FpUpLRc7sAylBEQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "eslint": ">=2.0.0" + } + }, "node_modules/eslint-plugin-prettier": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", diff --git a/package.json b/package.json index 825bc7b7..a7b498dd 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "eslint-plugin-json": "^3.1.0", + "eslint-plugin-no-catch-all": "^1.1.0", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", From 6e60d47e865e9670f24f1c876a15e6a6f5b78071 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 11 Nov 2024 16:56:22 +0100 Subject: [PATCH 2/2] fix all lint errors --- src/Components/AppShell/ContextWrapper.tsx | 1 + src/Components/Auth/useAuth.tsx | 1 + src/Components/Map/Subcomponents/Controls/SearchControl.tsx | 1 + src/Components/Map/Subcomponents/ItemFormPopup.tsx | 2 ++ src/Components/Map/Subcomponents/ItemViewPopup.tsx | 1 + src/Components/Map/hooks/useSelectPosition.tsx | 3 +++ src/Components/Profile/itemFunctions.ts | 4 ++++ src/Components/Templates/OverlayItemsIndexPage.tsx | 2 ++ src/Utils/ReverseGeocoder.ts | 1 + 9 files changed, 16 insertions(+) diff --git a/src/Components/AppShell/ContextWrapper.tsx b/src/Components/AppShell/ContextWrapper.tsx index 858834e6..cde23c2d 100644 --- a/src/Components/AppShell/ContextWrapper.tsx +++ b/src/Components/AppShell/ContextWrapper.tsx @@ -28,6 +28,7 @@ export const ContextWrapper = ({ children }) => { try { // eslint-disable-next-line react-hooks/rules-of-hooks location = useLocation() + // eslint-disable-next-line no-catch-all/no-catch-all } catch (e) { location = null } diff --git a/src/Components/Auth/useAuth.tsx b/src/Components/Auth/useAuth.tsx index 5e2a6755..5104c523 100644 --- a/src/Components/Auth/useAuth.tsx +++ b/src/Components/Auth/useAuth.tsx @@ -69,6 +69,7 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { setLoading(false) return me } else return undefined + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { setLoading(false) return undefined diff --git a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx index 6ad9404e..d84fbf62 100644 --- a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx +++ b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx @@ -63,6 +63,7 @@ export const SearchControl = () => { try { const { data } = await axios.get(`https://photon.komoot.io/api/?q=${value}&limit=5`) setGeoResults(data.features) + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { // eslint-disable-next-line no-console console.log(error) diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 09119a0f..405a3415 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -70,6 +70,7 @@ export function ItemFormPopup(props: ItemFormPopupProps) { try { await props.layer.api?.updateItem!({ ...formItem, id: props.item.id }) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -101,6 +102,7 @@ export function ItemFormPopup(props: ItemFormPopupProps) { name: formItem.name ? formItem.name : user?.first_name, })) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } diff --git a/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/src/Components/Map/Subcomponents/ItemViewPopup.tsx index f7aedff4..27464a54 100644 --- a/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -63,6 +63,7 @@ export const ItemViewPopup = forwardRef((props: ItemViewPopupProps, ref: any) => props.item.layer?.onlyOnePerOwner && (await props.item.layer.api?.updateItem!({ id: props.item.id, position: null })) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx index 310ce7ad..cc5409d1 100644 --- a/src/Components/Map/hooks/useSelectPosition.tsx +++ b/src/Components/Map/hooks/useSelectPosition.tsx @@ -89,6 +89,7 @@ function useSelectPositionManager(): { position: null, }) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -113,6 +114,7 @@ function useSelectPositionManager(): { position: updatedItem.position, }) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -134,6 +136,7 @@ function useSelectPositionManager(): { try { await markerClicked.layer?.api?.updateItem!(updatedItem) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index 3ad3d1d5..869aa686 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -62,6 +62,7 @@ export const submitNewItem = async ( await layer?.api?.createItem!({ ...formItem, id: uuid, type, parent: item.id }) await linkItem(uuid) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -83,6 +84,7 @@ export const linkItem = async (id: string, item, updateItem) => { try { await item?.layer?.api?.updateItem!(updatedItem) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -100,6 +102,7 @@ export const unlinkItem = async (id: string, item, updateItem) => { try { await item?.layer?.api?.updateItem!(updatedItem) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -123,6 +126,7 @@ export const handleDelete = async ( try { await item.layer?.api?.deleteItem!(item.id) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } diff --git a/src/Components/Templates/OverlayItemsIndexPage.tsx b/src/Components/Templates/OverlayItemsIndexPage.tsx index 291abbd4..1496dbdb 100644 --- a/src/Components/Templates/OverlayItemsIndexPage.tsx +++ b/src/Components/Templates/OverlayItemsIndexPage.tsx @@ -91,6 +91,7 @@ export const OverlayItemsIndexPage = ({ try { await layer?.api?.createItem!({ ...formItem, id: uuid }) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } @@ -108,6 +109,7 @@ export const OverlayItemsIndexPage = ({ try { await layer?.api?.deleteItem!(item.id) success = true + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { toast.error(error.toString()) } diff --git a/src/Utils/ReverseGeocoder.ts b/src/Utils/ReverseGeocoder.ts index 627626cf..ca227063 100644 --- a/src/Utils/ReverseGeocoder.ts +++ b/src/Utils/ReverseGeocoder.ts @@ -34,6 +34,7 @@ export async function reverseGeocode(lat: number, lon: number): Promise // Formatiere die Adresse const formattedAddress = `${street} ${houseNumber}, ${city}`.trim() return formattedAddress || '' + // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { // eslint-disable-next-line no-console console.error('Error:', error)