From ed7a9dbc23f9ba52545ca35815090b8016f4eaaf Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 18 Jul 2024 16:18:23 -0600 Subject: [PATCH] Fix permission-controller lint violations (#4537) There are some `permission-controller` tests which attempt to push an async middleware function onto an engine. Although this works in practice, `@typescript-eslint` balks at this, because the type for `JsonRpcEngine.push` says it takes a `JsonRpcMiddleware`, and a `JsonRpcMiddleware` has a return type of `void`, not `Promise`. We could change that return type to `void | Promise` but that would cause other changes we may not want to make. So this commit merely ignores the lint violations. This should be safe because `JsonRpcEngine` doesn't await middleware anyway. Interestingly, the lint violations caused by this discrepancy only appear locally and not on CI. I am not sure why this is. --- .../src/rpc-methods/getPermissions.test.ts | 14 +++++--- .../rpc-methods/requestPermissions.test.ts | 14 +++++--- .../src/rpc-methods/revokePermissions.test.ts | 35 +++++++++++++------ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/packages/permission-controller/src/rpc-methods/getPermissions.test.ts b/packages/permission-controller/src/rpc-methods/getPermissions.test.ts index 99e0d02c48..f7724f4617 100644 --- a/packages/permission-controller/src/rpc-methods/getPermissions.test.ts +++ b/packages/permission-controller/src/rpc-methods/getPermissions.test.ts @@ -14,13 +14,16 @@ describe('getPermissions RPC method', () => { const engine = new JsonRpcEngine(); engine.push( - async ( + ( req: JsonRpcRequest<[]>, res: PendingJsonRpcResponse, next, end, ) => { - await implementation(req, res, next, end, { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { getPermissionsForOrigin: mockGetPermissionsForOrigin, }); }, @@ -44,13 +47,16 @@ describe('getPermissions RPC method', () => { const engine = new JsonRpcEngine(); engine.push( - async ( + ( req: JsonRpcRequest<[]>, res: PendingJsonRpcResponse, next, end, ) => { - await implementation(req, res, next, end, { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { getPermissionsForOrigin: mockGetPermissionsForOrigin, }); }, diff --git a/packages/permission-controller/src/rpc-methods/requestPermissions.test.ts b/packages/permission-controller/src/rpc-methods/requestPermissions.test.ts index 6d467910d1..77dfc93ae5 100644 --- a/packages/permission-controller/src/rpc-methods/requestPermissions.test.ts +++ b/packages/permission-controller/src/rpc-methods/requestPermissions.test.ts @@ -32,8 +32,11 @@ describe('requestPermissions RPC method', () => { const engine = new JsonRpcEngine(); engine.push<[RequestedPermissions], PermissionConstraint[]>( - async (req, res, next, end) => { - await implementation(req, res, next, end, { + (req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { requestPermissionsForOrigin: mockRequestPermissionsForOrigin, }); }, @@ -102,8 +105,11 @@ describe('requestPermissions RPC method', () => { const engine = new JsonRpcEngine(); engine.push<[RequestedPermissions], PermissionConstraint[]>( - async (req, res, next, end) => { - await implementation(req, res, next, end, { + (req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { requestPermissionsForOrigin: mockRequestPermissionsForOrigin, }); }, diff --git a/packages/permission-controller/src/rpc-methods/revokePermissions.test.ts b/packages/permission-controller/src/rpc-methods/revokePermissions.test.ts index 8a77226df5..5d9a9fdc21 100644 --- a/packages/permission-controller/src/rpc-methods/revokePermissions.test.ts +++ b/packages/permission-controller/src/rpc-methods/revokePermissions.test.ts @@ -27,8 +27,11 @@ describe('revokePermissions RPC method', () => { const mockRevokePermissionsForOrigin = jest.fn(); const engine = new JsonRpcEngine(); - engine.push(async (req, res, next, end) => { - await implementation(req, res, next, end, { + engine.push((req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { revokePermissionsForOrigin: mockRevokePermissionsForOrigin, }); }); @@ -57,8 +60,11 @@ describe('revokePermissions RPC method', () => { const mockRevokePermissionsForOrigin = jest.fn(); const engine = new JsonRpcEngine(); - engine.push(async (req, res, next, end) => { - await implementation(req, res, next, end, { + engine.push((req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { revokePermissionsForOrigin: mockRevokePermissionsForOrigin, }); }); @@ -91,8 +97,11 @@ describe('revokePermissions RPC method', () => { const mockRevokePermissionsForOrigin = jest.fn(); const engine = new JsonRpcEngine(); - engine.push(async (req, res, next, end) => { - await implementation(req, res, next, end, { + engine.push((req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { revokePermissionsForOrigin: mockRevokePermissionsForOrigin, }); }); @@ -125,8 +134,11 @@ describe('revokePermissions RPC method', () => { const mockRevokePermissionsForOrigin = jest.fn(); const engine = new JsonRpcEngine(); - engine.push(async (req, res, next, end) => { - await implementation(req, res, next, end, { + engine.push((req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { revokePermissionsForOrigin: mockRevokePermissionsForOrigin, }); }); @@ -158,8 +170,11 @@ describe('revokePermissions RPC method', () => { const mockRevokePermissionsForOrigin = jest.fn(); const engine = new JsonRpcEngine(); - engine.push(async (req, res, next, end) => { - await implementation(req, res, next, end, { + engine.push((req, res, next, end) => { + // We intentionally do not await this promise; JsonRpcEngine won't await + // middleware anyway. + // eslint-disable-next-line @typescript-eslint/no-floating-promises + implementation(req, res, next, end, { revokePermissionsForOrigin: mockRevokePermissionsForOrigin, }); });