From 7e74439c51646718af8f00da063c0e9989c084ff Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Fri, 1 Sep 2023 09:49:33 +0200 Subject: [PATCH] chore: enable 'return-await` (#10832) --- .eslintrc.js | 2 ++ .github/workflows/ci.yml | 4 +-- packages/browsers/src/launch.ts | 2 +- .../puppeteer-core/src/api/ElementHandle.ts | 22 ++++++------- packages/puppeteer-core/src/api/Frame.ts | 14 ++++---- packages/puppeteer-core/src/api/Page.ts | 16 +++++----- packages/puppeteer-core/src/api/Realm.ts | 2 +- .../src/common/AriaQueryHandler.ts | 2 +- packages/puppeteer-core/src/common/Browser.ts | 2 +- .../src/common/DeviceRequestPrompt.ts | 4 +-- .../src/common/ElementHandle.ts | 8 ++--- .../src/common/ExecutionContext.ts | 4 +-- packages/puppeteer-core/src/common/Frame.ts | 2 +- .../puppeteer-core/src/common/HTTPRequest.ts | 12 +++---- packages/puppeteer-core/src/common/Input.ts | 2 +- .../src/common/IsolatedWorld.ts | 4 +-- .../puppeteer-core/src/common/JSHandle.ts | 2 +- packages/puppeteer-core/src/common/LazyArg.ts | 2 +- packages/puppeteer-core/src/common/Page.ts | 32 ++++++++++--------- packages/puppeteer-core/src/common/Target.ts | 2 +- packages/puppeteer-core/src/common/Tracing.ts | 2 +- .../puppeteer-core/src/common/WebWorker.ts | 6 ++-- .../src/common/bidi/BrowsingContext.ts | 2 +- .../src/common/bidi/JSHandle.ts | 2 +- .../puppeteer-core/src/common/bidi/Page.ts | 8 ++--- .../puppeteer-core/src/common/bidi/Realm.ts | 4 +-- .../puppeteer-core/src/common/bidi/Sandbox.ts | 4 +-- packages/puppeteer-core/src/common/util.ts | 2 +- test/src/ariaqueryhandler.spec.ts | 2 +- test/src/elementhandle.spec.ts | 4 +-- test/src/evaluation.spec.ts | 2 +- test/src/input.spec.ts | 4 +-- test/src/network.spec.ts | 4 +-- test/src/page.spec.ts | 22 +++++++------ tools/internal/job.ts | 10 +++--- 35 files changed, 112 insertions(+), 106 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index bdb925af..76c19cdd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -218,6 +218,8 @@ module.exports = { {ignoreVoid: true, ignoreIIFE: true}, ], '@typescript-eslint/prefer-ts-expect-error': 'error', + // This is more performant; see https://v8.dev/blog/fast-async. + '@typescript-eslint/return-await': ['error', 'always'], }, overrides: [ { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 630e289b..12cc259b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,12 +37,12 @@ jobs: - uses: google/wireit@f3a3c79c553122e2fe5829eeac7d815326502903 # setup-github-actions-caching/v1 - name: Check code run: npm run check - - name: Lint code - run: npm run lint - name: Validate licenses run: npm run validate-licenses - name: Build every package run: npm run build + - name: Lint code + run: npm run lint - name: Generate documents run: npm run docs - name: Check if autogenerated docs differ diff --git a/packages/browsers/src/launch.ts b/packages/browsers/src/launch.ts index e47f14ae..f00cd0b1 100644 --- a/packages/browsers/src/launch.ts +++ b/packages/browsers/src/launch.ts @@ -305,7 +305,7 @@ export class Process { if (!this.#exited) { this.kill(); } - return this.#browserProcessExiting; + return await this.#browserProcessExiting; } hasClosed(): Promise { diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index 0a804cd2..b8aa7cab 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -179,14 +179,14 @@ export abstract class ElementHandle< override async getProperty( propertyName: HandleOr ): Promise> { - return this.handle.getProperty(propertyName); + return await this.handle.getProperty(propertyName); } /** * @internal */ override async getProperties(): Promise> { - return this.handle.getProperties(); + return await this.handle.getProperties(); } /** @@ -202,7 +202,7 @@ export abstract class ElementHandle< pageFunction: Func | string, ...args: Params ): Promise>> { - return this.handle.evaluate(pageFunction, ...args); + return await this.handle.evaluate(pageFunction, ...args); } /** @@ -225,7 +225,7 @@ export abstract class ElementHandle< * @internal */ override async jsonValue(): Promise { - return this.handle.jsonValue(); + return await this.handle.jsonValue(); } /** @@ -288,9 +288,9 @@ export abstract class ElementHandle< ): Promise>>> { const {updatedSelector, QueryHandler} = getQueryHandlerAndSelector(selector); - return AsyncIterableUtil.collect( + return await (AsyncIterableUtil.collect( QueryHandler.queryAll(this, updatedSelector) - ) as Promise>>>; + ) as Promise>>>); } /** @@ -419,7 +419,7 @@ export abstract class ElementHandle< if (expression.startsWith('//')) { expression = `.${expression}`; } - return this.$$(`xpath/${expression}`); + return await this.$$(`xpath/${expression}`); } /** @@ -491,7 +491,7 @@ export abstract class ElementHandle< * {@link ElementHandle.waitForSelector}. */ async isVisible(): Promise { - return this.#checkVisibility(true); + return await this.#checkVisibility(true); } /** @@ -499,7 +499,7 @@ export abstract class ElementHandle< * {@link ElementHandle.waitForSelector}. */ async isHidden(): Promise { - return this.#checkVisibility(false); + return await this.#checkVisibility(false); } /** @@ -575,7 +575,7 @@ export abstract class ElementHandle< if (xpath.startsWith('//')) { xpath = `.${xpath}`; } - return this.waitForSelector(`xpath/${xpath}`, options); + return await this.waitForSelector(`xpath/${xpath}`, options); } /** @@ -745,7 +745,7 @@ export abstract class ElementHandle< ); } - return this.evaluate((element, vals): string[] => { + return await this.evaluate((element, vals): string[] => { const values = new Set(vals); if (!(element instanceof HTMLSelectElement)) { throw new Error('Element is not a