From 97c3ef867ef768a8ffad48d58a19aa418394ad80 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 9 Nov 2024 00:40:44 +0100 Subject: [PATCH 1/3] promise linting --- .eslintrc.js | 32 ++++++++++++++++---------------- package-lock.json | 20 +++++++++++++++++++- package.json | 2 ++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3836ab1a..b16fbb01 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -23,7 +23,7 @@ module.exports = { plugins: [ '@typescript-eslint', 'import', - // 'promise', + 'promise', // 'security', // 'no-catch-all', 'react', @@ -122,21 +122,21 @@ module.exports = { }, ], 'import/prefer-default-export': 'off', - // // promise - // 'promise/catch-or-return': 'error', - // 'promise/no-return-wrap': 'error', - // 'promise/param-names': 'error', - // 'promise/always-return': 'error', - // 'promise/no-native': 'off', - // 'promise/no-nesting': 'warn', - // 'promise/no-promise-in-callback': 'warn', - // 'promise/no-callback-in-promise': 'warn', - // 'promise/avoid-new': 'warn', - // 'promise/no-new-statics': 'error', - // 'promise/no-return-in-finally': 'warn', - // 'promise/valid-params': 'warn', - // 'promise/prefer-await-to-callbacks': 'error', - // 'promise/no-multiple-resolved': 'error', + // promise + 'promise/catch-or-return': 'error', + 'promise/no-return-wrap': 'error', + 'promise/param-names': 'error', + 'promise/always-return': 'error', + 'promise/no-native': 'off', + 'promise/no-nesting': 'warn', + 'promise/no-promise-in-callback': 'warn', + 'promise/no-callback-in-promise': 'warn', + 'promise/avoid-new': 'warn', + 'promise/no-new-statics': 'error', + 'promise/no-return-in-finally': 'warn', + 'promise/valid-params': 'warn', + 'promise/prefer-await-to-callbacks': 'error', + 'promise/no-multiple-resolved': 'error', }, overrides: [ { diff --git a/package-lock.json b/package-lock.json index 74187848..e5f9cdab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1", "@types/geojson": "^7946.0.14", "@types/leaflet": "^1.7.11", + "@types/node": "^20.12.1", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.62.0", @@ -46,6 +47,7 @@ "eslint-plugin-import": "^2.31.0", "eslint-plugin-json": "^3.1.0", "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-yml": "^1.14.0", @@ -453,6 +455,16 @@ "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" }, + "node_modules/@types/node": { + "version": "20.12.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.1.tgz", + "integrity": "sha512-5lcxgB72hlSF7ZS9ZzX1RCLc9+BovxjL17T00xSmj3c0ygZFjPdNnN0RchfGpot/yniVMkWnyO6aR9Dr1q9qrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/offscreencanvas": { "version": "2019.7.1", "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.1.tgz", @@ -2408,7 +2420,6 @@ "integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -7157,6 +7168,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "license": "MIT" + }, "node_modules/unified": { "version": "11.0.4", "resolved": "https://registry.npmjs.org/unified/-/unified-11.0.4.tgz", diff --git a/package.json b/package.json index 825bc7b7..5fb22ce0 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1", "@types/geojson": "^7946.0.14", "@types/leaflet": "^1.7.11", + "@types/node": "^20.12.1", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.62.0", @@ -34,6 +35,7 @@ "eslint-plugin-import": "^2.31.0", "eslint-plugin-json": "^3.1.0", "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-yml": "^1.14.0", From 782b0fc700842fa2877074839a8c5f7d8cff3163 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 9 Nov 2024 00:40:54 +0100 Subject: [PATCH 2/3] fix errors --- src/Components/Profile/ProfileView.tsx | 2 ++ src/Components/Profile/Subcomponents/SocialShareBar.tsx | 2 ++ src/Components/Profile/UserSettings.tsx | 4 +++- src/Components/Profile/itemFunctions.ts | 8 +++++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index a54ae222..ec98a677 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -63,7 +63,9 @@ export function ProfileView({ attestationApi }: { attestationApi?: ItemsApi console.log(value) setAttestations(value) + return null }) + // eslint-disable-next-line promise/prefer-await-to-callbacks .catch((error) => { console.error('Error fetching items:', error) }) diff --git a/src/Components/Profile/Subcomponents/SocialShareBar.tsx b/src/Components/Profile/Subcomponents/SocialShareBar.tsx index 13b94910..150fde40 100644 --- a/src/Components/Profile/Subcomponents/SocialShareBar.tsx +++ b/src/Components/Profile/Subcomponents/SocialShareBar.tsx @@ -16,7 +16,9 @@ const SocialShareBar = ({ .writeText(url) .then(() => { toast.success('link copied to clipboard') + return null }) + // eslint-disable-next-line promise/prefer-await-to-callbacks .catch((error: never) => { toast.error('Fehler beim Kopieren des Links: ', error) }) diff --git a/src/Components/Profile/UserSettings.tsx b/src/Components/Profile/UserSettings.tsx index 88d644e7..e98896cd 100644 --- a/src/Components/Profile/UserSettings.tsx +++ b/src/Components/Profile/UserSettings.tsx @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' @@ -43,6 +42,9 @@ export function UserSettings() { }, }) .then(() => navigate('/')) + .catch((e) => { + throw e + }) } return ( diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index 3ad3d1d5..d1f35043 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -9,6 +9,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ +import { setTimeout } from 'timers/promises' + import { toast } from 'react-toastify' import { Item } from '#src/types' @@ -16,8 +18,6 @@ import { encodeTag } from '#utils/FormatTags' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' -const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) - export const submitNewItem = async ( evt: any, type: string, @@ -224,7 +224,7 @@ export const onUpdateItem = async ( }) // take care that addTag request comes before item request - await sleep(200) + await setTimeout(200) if (!item.new) { item?.layer?.api?.updateItem && @@ -243,6 +243,7 @@ export const onUpdateItem = async ( .then(() => { setLoading(false) navigate(`/item/${item.id}${params && '?' + params}`) + return null }) } else { item.new = false @@ -272,6 +273,7 @@ export const onUpdateItem = async ( .then(() => { setLoading(false) navigate(`/${params && '?' + params}`) + return null }) } } From e84061178fc8116bebafbeddcf35f8d635fb5e18 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 12 Nov 2024 09:26:57 +0100 Subject: [PATCH 3/3] remove node environment requirement --- package-lock.json | 18 ------------------ package.json | 1 - src/Components/Profile/itemFunctions.ts | 7 ++++--- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5f9cdab..e41b659a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,6 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1", "@types/geojson": "^7946.0.14", "@types/leaflet": "^1.7.11", - "@types/node": "^20.12.1", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.62.0", @@ -455,16 +454,6 @@ "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" }, - "node_modules/@types/node": { - "version": "20.12.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.1.tgz", - "integrity": "sha512-5lcxgB72hlSF7ZS9ZzX1RCLc9+BovxjL17T00xSmj3c0ygZFjPdNnN0RchfGpot/yniVMkWnyO6aR9Dr1q9qrg==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~5.26.4" - } - }, "node_modules/@types/offscreencanvas": { "version": "2019.7.1", "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.1.tgz", @@ -7168,13 +7157,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true, - "license": "MIT" - }, "node_modules/unified": { "version": "11.0.4", "resolved": "https://registry.npmjs.org/unified/-/unified-11.0.4.tgz", diff --git a/package.json b/package.json index 5fb22ce0..62f70c92 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1", "@types/geojson": "^7946.0.14", "@types/leaflet": "^1.7.11", - "@types/node": "^20.12.1", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.5", "@typescript-eslint/eslint-plugin": "^5.62.0", diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index d1f35043..b9baa1d4 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -9,8 +9,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { setTimeout } from 'timers/promises' - import { toast } from 'react-toastify' import { Item } from '#src/types' @@ -18,6 +16,9 @@ import { encodeTag } from '#utils/FormatTags' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' +// eslint-disable-next-line promise/avoid-new +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) + export const submitNewItem = async ( evt: any, type: string, @@ -224,7 +225,7 @@ export const onUpdateItem = async ( }) // take care that addTag request comes before item request - await setTimeout(200) + await sleep(200) if (!item.new) { item?.layer?.api?.updateItem &&