From 45690c2756fa222b22d7527bfbfec33632426374 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 29 Nov 2023 04:43:46 +0000 Subject: [PATCH] fix: add no-useless-promise-resolve-reject rule (#5111) --- .eslintrc.js | 1 + package.json | 2 +- packages/backend/server/tests/workspace-usage.spec.ts | 4 +--- packages/frontend/core/src/bootstrap/register-plugins.ts | 6 +++--- packages/frontend/graphql/src/fetcher.ts | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fc7888a091..fd49734c02 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -210,6 +210,7 @@ const config = { 'unicorn/prefer-dom-node-dataset': 'error', 'unicorn/prefer-dom-node-append': 'error', 'unicorn/prefer-array-some': 'error', + 'unicorn/no-useless-promise-resolve-reject': 'error', 'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-element-overwrite': 'error', 'sonarjs/no-empty-collection': 'error', diff --git a/package.json b/package.json index 5a18431c61..78cf773d3b 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lint:eslint:fix": "yarn lint:eslint --fix", "lint:prettier": "prettier --ignore-unknown --cache --check .", "lint:prettier:fix": "prettier --ignore-unknown --cache --write .", - "lint:ox": "oxlint --deny-warnings --import-plugin -D correctness -D nursery -D prefer-array-some -A no-undef -A consistent-type-exports -A default -A named -A ban-ts-comment", + "lint:ox": "oxlint --deny-warnings --import-plugin -D correctness -D nursery -D prefer-array-some -D no-useless-promise-resolve-reject -A no-undef -A consistent-type-exports -A default -A named -A ban-ts-comment", "lint": "yarn lint:eslint && yarn lint:prettier", "lint:fix": "yarn lint:eslint:fix && yarn lint:prettier:fix", "test": "vitest --run", diff --git a/packages/backend/server/tests/workspace-usage.spec.ts b/packages/backend/server/tests/workspace-usage.spec.ts index 6cda0e2ad2..a7051b1eb0 100644 --- a/packages/backend/server/tests/workspace-usage.spec.ts +++ b/packages/backend/server/tests/workspace-usage.spec.ts @@ -65,9 +65,7 @@ test.afterEach.always(async t => { test('should get blob size limit', async t => { const { resolver } = t.context; - fakeUserService.getStorageQuotaById.returns( - Promise.resolve(100 * 1024 * 1024 * 1024) - ); + fakeUserService.getStorageQuotaById.resolves(100 * 1024 * 1024 * 1024); const res = await resolver.checkBlobSize(new FakePrisma().fakeUser, '', 100); t.not(res, false); // @ts-expect-error diff --git a/packages/frontend/core/src/bootstrap/register-plugins.ts b/packages/frontend/core/src/bootstrap/register-plugins.ts index be6cf1c998..348208f60b 100644 --- a/packages/frontend/core/src/bootstrap/register-plugins.ts +++ b/packages/frontend/core/src/bootstrap/register-plugins.ts @@ -81,7 +81,7 @@ export async function bootstrapPluginSystem( logger.debug(`registering plugin ${pluginName}`); logger.debug(`package.json: ${packageJson}`); if (!release && !runtimeConfig.enablePlugin) { - return Promise.resolve(); + return; } const baseURL = url; const entryURL = `${baseURL}/${core}`; @@ -95,7 +95,7 @@ export async function bootstrapPluginSystem( const loadedAssetName = `${pluginName}_${asset}`; // todo(himself65): add assets into shadow dom if (loadedAssets.has(loadedAssetName)) { - return Promise.resolve(); + return; } if (asset.endsWith('.css')) { loadedAssets.add(loadedAssetName); @@ -111,7 +111,7 @@ export async function bootstrapPluginSystem( } return null; } else { - return Promise.resolve(); + return; } }) ); diff --git a/packages/frontend/graphql/src/fetcher.ts b/packages/frontend/graphql/src/fetcher.ts index 4015f96e74..2c2e6f0198 100644 --- a/packages/frontend/graphql/src/fetcher.ts +++ b/packages/frontend/graphql/src/fetcher.ts @@ -255,6 +255,6 @@ export const fetchWithTraceReport = async ( requestId, ...(event ? { event } : {}), }); - return await Promise.reject(err); + throw err; } };