From 7ccb7063a97d114c4f4b881f6402002de7aec2f3 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 22 Jun 2023 11:49:18 -0400 Subject: [PATCH] feat(eslint): Add `no-return-await` rule to eslint config --- packages/browser-integration-tests/utils/helpers.ts | 2 +- packages/browser-integration-tests/utils/replayHelpers.ts | 4 ++-- packages/e2e-tests/test-utils/event-proxy-server.ts | 4 ++-- packages/eslint-config-sdk/src/index.js | 3 +++ .../nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts | 4 ++-- .../src/client/wrapDocumentGetInitialPropsWithSentry.ts | 4 ++-- .../nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts | 4 ++-- packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts | 4 ++-- .../nextjs/src/client/wrapGetServerSidePropsWithSentry.ts | 4 ++-- packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts | 4 ++-- .../nextjs/src/common/devErrorSymbolicationEventProcessor.ts | 2 +- packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts | 4 ++-- packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts | 2 +- packages/nextjs/src/server/wrapApiHandlerWithSentry.ts | 4 ++-- .../src/server/wrapDocumentGetInitialPropsWithSentry.ts | 4 ++-- packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts | 2 +- packages/replay/src/util/sendReplay.ts | 2 +- packages/replay/test/integration/flush.test.ts | 4 ++-- packages/sveltekit/src/vite/svelteConfig.ts | 2 +- packages/utils/test/buildPolyfills/originals.js | 4 ++-- 20 files changed, 35 insertions(+), 32 deletions(-) diff --git a/packages/browser-integration-tests/utils/helpers.ts b/packages/browser-integration-tests/utils/helpers.ts index 296b2fcdba91..525877e9763f 100644 --- a/packages/browser-integration-tests/utils/helpers.ts +++ b/packages/browser-integration-tests/utils/helpers.ts @@ -268,7 +268,7 @@ async function injectScriptAndGetEvents(page: Page, url: string, scriptPath: str await page.goto(url); await runScriptInSandbox(page, scriptPath); - return await getSentryEvents(page); + return getSentryEvents(page); } export { diff --git a/packages/browser-integration-tests/utils/replayHelpers.ts b/packages/browser-integration-tests/utils/replayHelpers.ts index ec332edea74d..bf070b395cf6 100644 --- a/packages/browser-integration-tests/utils/replayHelpers.ts +++ b/packages/browser-integration-tests/utils/replayHelpers.ts @@ -132,14 +132,14 @@ export async function waitForReplayRunning(page: Page): Promise { * Note that due to how this works with playwright, this is a POJO copy of replay. * This means that we cannot access any methods on it, and also not mutate it in any way. */ -export async function getReplaySnapshot(page: Page): Promise<{ +export function getReplaySnapshot(page: Page): Promise<{ _isPaused: boolean; _isEnabled: boolean; _context: InternalEventContext; session: Session | undefined; recordingMode: ReplayRecordingMode; }> { - return await page.evaluate(() => { + return page.evaluate(() => { const replayIntegration = (window as unknown as Window & { Replay: { _replay: ReplayContainer } }).Replay; const replay = replayIntegration._replay; diff --git a/packages/e2e-tests/test-utils/event-proxy-server.ts b/packages/e2e-tests/test-utils/event-proxy-server.ts index c61e20d4081d..b32910480f38 100644 --- a/packages/e2e-tests/test-utils/event-proxy-server.ts +++ b/packages/e2e-tests/test-utils/event-proxy-server.ts @@ -243,7 +243,7 @@ async function registerCallbackServerPort(serverName: string, port: string): Pro await writeFile(tmpFilePath, port, { encoding: 'utf8' }); } -async function retrieveCallbackServerPort(serverName: string): Promise { +function retrieveCallbackServerPort(serverName: string): Promise { const tmpFilePath = path.join(os.tmpdir(), `${TEMP_FILE_PREFIX}${serverName}`); - return await readFile(tmpFilePath, 'utf8'); + return readFile(tmpFilePath, 'utf8'); } diff --git a/packages/eslint-config-sdk/src/index.js b/packages/eslint-config-sdk/src/index.js index 05ec68cff509..c070195ed083 100644 --- a/packages/eslint-config-sdk/src/index.js +++ b/packages/eslint-config-sdk/src/index.js @@ -261,5 +261,8 @@ module.exports = { 'array-callback-return': ['error', { allowImplicit: true }], quotes: ['error', 'single', { avoidEscape: true }], + + // Remove uncessary usages of async await to prevent extra micro-tasks + 'no-return-await': 'error', }, }; diff --git a/packages/nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts b/packages/nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts index 8c757be6a3c8..e5f8c40847ff 100644 --- a/packages/nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts @@ -8,8 +8,8 @@ type AppGetInitialProps = (typeof App)['getInitialProps']; */ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetInitialProps): AppGetInitialProps { return new Proxy(origAppGetInitialProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/client/wrapDocumentGetInitialPropsWithSentry.ts b/packages/nextjs/src/client/wrapDocumentGetInitialPropsWithSentry.ts index 0af40a1f3f84..20669a0af9f6 100644 --- a/packages/nextjs/src/client/wrapDocumentGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapDocumentGetInitialPropsWithSentry.ts @@ -10,8 +10,8 @@ export function wrapDocumentGetInitialPropsWithSentry( origDocumentGetInitialProps: DocumentGetInitialProps, ): DocumentGetInitialProps { return new Proxy(origDocumentGetInitialProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts b/packages/nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts index 605efa58eff9..ab32a2bf93cc 100644 --- a/packages/nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts @@ -11,8 +11,8 @@ export function wrapErrorGetInitialPropsWithSentry( origErrorGetInitialProps: ErrorGetInitialProps, ): ErrorGetInitialProps { return new Proxy(origErrorGetInitialProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts b/packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts index 1fbbd8707063..37004f04bc6e 100644 --- a/packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts @@ -8,8 +8,8 @@ type GetInitialProps = Required['getInitialProps']; */ export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialProps): GetInitialProps { return new Proxy(origGetInitialProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/client/wrapGetServerSidePropsWithSentry.ts b/packages/nextjs/src/client/wrapGetServerSidePropsWithSentry.ts index 2235016856f4..50450c053a15 100644 --- a/packages/nextjs/src/client/wrapGetServerSidePropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapGetServerSidePropsWithSentry.ts @@ -6,8 +6,8 @@ import type { GetServerSideProps } from 'next'; */ export function wrapGetServerSidePropsWithSentry(origGetServerSideProps: GetServerSideProps): GetServerSideProps { return new Proxy(origGetServerSideProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts b/packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts index 735a3cd8a936..3b99737bcf20 100644 --- a/packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts +++ b/packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts @@ -8,8 +8,8 @@ type Props = { [key: string]: unknown }; */ export function wrapGetStaticPropsWithSentry(origGetStaticProps: GetStaticProps): GetStaticProps { return new Proxy(origGetStaticProps, { - apply: async (wrappingTarget, thisArg, args: Parameters>) => { - return await wrappingTarget.apply(thisArg, args); + apply: (wrappingTarget, thisArg, args: Parameters>) => { + return wrappingTarget.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts b/packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts index 7e3fd8baae24..d516780c0257 100644 --- a/packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts +++ b/packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts @@ -116,7 +116,7 @@ export async function devErrorSymbolicationEventProcessor(event: Event, hint: Ev const frames = stackTraceParser.parse(hint.originalException.stack); const resolvedFrames = await Promise.all( - frames.map(async frame => await resolveStackFrame(frame, hint.originalException as Error)), + frames.map(frame => resolveStackFrame(frame, hint.originalException as Error)), ); if (event.exception?.values?.[0].stacktrace?.frames) { diff --git a/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts b/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts index ef228abc40e9..ebfdbf5fdf74 100644 --- a/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts +++ b/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts @@ -11,7 +11,7 @@ export function wrapApiHandlerWithSentry( parameterizedRoute: string, ): (...params: Parameters) => Promise> { return new Proxy(handler, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { + apply: (wrappingTarget, thisArg, args: Parameters) => { const req = args[0]; const activeSpan = !!getCurrentHub().getScope()?.getSpan(); @@ -25,7 +25,7 @@ export function wrapApiHandlerWithSentry( mechanismFunctionName: 'wrapApiHandlerWithSentry', }); - return await wrappedHandler.apply(thisArg, args); + return wrappedHandler.apply(thisArg, args); }, }); } diff --git a/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts b/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts index 18c16f1a4198..831a50eb8629 100644 --- a/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts +++ b/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts @@ -11,7 +11,7 @@ export function wrapMiddlewareWithSentry( middleware: H, ): (...params: Parameters) => Promise> { return new Proxy(middleware, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { + apply: (wrappingTarget, thisArg, args: Parameters) => { return withEdgeWrapping(wrappingTarget, { spanDescription: 'middleware', spanOp: 'middleware.nextjs', diff --git a/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts index 3ebf97d4b614..9aecbd9a6c6b 100644 --- a/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts +++ b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts @@ -26,7 +26,7 @@ import { autoEndTransactionOnResponseEnd, finishTransaction, flushQueue } from ' */ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameterizedRoute: string): NextApiHandler { return new Proxy(apiHandler, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { + apply: (wrappingTarget, thisArg, args: Parameters) => { // eslint-disable-next-line deprecation/deprecation return withSentry(wrappingTarget, parameterizedRoute).apply(thisArg, args); }, @@ -49,7 +49,7 @@ export const withSentryAPI = wrapApiHandlerWithSentry; */ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: string): NextApiHandler { return new Proxy(apiHandler, { - apply: async (wrappingTarget, thisArg, args: [AugmentedNextApiRequest, AugmentedNextApiResponse]) => { + apply: (wrappingTarget, thisArg, args: [AugmentedNextApiRequest, AugmentedNextApiResponse]) => { const [req, res] = args; // We're now auto-wrapping API route handlers using `wrapApiHandlerWithSentry` (which uses `withSentry` under the hood), but diff --git a/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts b/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts index e7d0d6eac621..1d821d86dcda 100644 --- a/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts @@ -19,7 +19,7 @@ export function wrapDocumentGetInitialPropsWithSentry( origDocumentGetInitialProps: DocumentGetInitialProps, ): DocumentGetInitialProps { return new Proxy(origDocumentGetInitialProps, { - apply: async (wrappingTarget, thisArg, args: Parameters) => { + apply: (wrappingTarget, thisArg, args: Parameters) => { if (isBuild()) { return wrappingTarget.apply(thisArg, args); } @@ -41,7 +41,7 @@ export function wrapDocumentGetInitialPropsWithSentry( dataFetchingMethodName: 'getInitialProps', }); - return await tracedGetInitialProps.apply(thisArg, args); + return tracedGetInitialProps.apply(thisArg, args); } else { return errorWrappedGetInitialProps.apply(thisArg, args); } diff --git a/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts b/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts index d8c7cc8f68ab..78f910dfb0e4 100644 --- a/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts +++ b/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts @@ -19,7 +19,7 @@ export function wrapGetStaticPropsWithSentry( parameterizedRoute: string, ): GetStaticProps { return new Proxy(origGetStaticPropsa, { - apply: async (wrappingTarget, thisArg, args: Parameters>) => { + apply: (wrappingTarget, thisArg, args: Parameters>) => { if (isBuild()) { return wrappingTarget.apply(thisArg, args); } diff --git a/packages/replay/src/util/sendReplay.ts b/packages/replay/src/util/sendReplay.ts index f10bb223d3d9..5f10011182c6 100644 --- a/packages/replay/src/util/sendReplay.ts +++ b/packages/replay/src/util/sendReplay.ts @@ -57,7 +57,7 @@ export async function sendReplay( // will retry in intervals of 5, 10, 30 retryConfig.interval *= ++retryConfig.count; - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { setTimeout(async () => { try { await sendReplay(replayData, retryConfig); diff --git a/packages/replay/test/integration/flush.test.ts b/packages/replay/test/integration/flush.test.ts index 18c7a86ca188..cf142ae8c45c 100644 --- a/packages/replay/test/integration/flush.test.ts +++ b/packages/replay/test/integration/flush.test.ts @@ -135,8 +135,8 @@ describe('Integration | flush', () => { it('long first flush enqueues following events', async () => { // Mock this to resolve after 20 seconds so that we can queue up following flushes - mockAddPerformanceEntries.mockImplementationOnce(async () => { - return await new Promise(resolve => setTimeout(resolve, 20000)); + mockAddPerformanceEntries.mockImplementationOnce(() => { + return new Promise(resolve => setTimeout(resolve, 20000)); }); expect(mockAddPerformanceEntries).not.toHaveBeenCalled(); diff --git a/packages/sveltekit/src/vite/svelteConfig.ts b/packages/sveltekit/src/vite/svelteConfig.ts index 07c701e912f1..4e69ad8ef3b0 100644 --- a/packages/sveltekit/src/vite/svelteConfig.ts +++ b/packages/sveltekit/src/vite/svelteConfig.ts @@ -52,7 +52,7 @@ export function getHooksFileName(svelteConfig: Config, hookType: 'client' | 'ser */ export async function getAdapterOutputDir(svelteConfig: Config, adapter: SupportedSvelteKitAdapters): Promise { if (adapter === 'node') { - return await getNodeAdapterOutputDir(svelteConfig); + return getNodeAdapterOutputDir(svelteConfig); } // Auto and Vercel adapters simply use config.kit.outDir diff --git a/packages/utils/test/buildPolyfills/originals.js b/packages/utils/test/buildPolyfills/originals.js index d3dcb22e8082..969591755367 100644 --- a/packages/utils/test/buildPolyfills/originals.js +++ b/packages/utils/test/buildPolyfills/originals.js @@ -2,11 +2,11 @@ // the modified versions do the same thing the originals do. // From Sucrase -export async function _asyncNullishCoalesce(lhs, rhsFn) { +export function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { - return await rhsFn(); + return rhsFn(); } }