From e89212b43534d32e944bf445e2e7d2325df23c36 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 17 Jun 2023 13:27:51 +0300 Subject: [PATCH] Remove some eslint overrides (#5676) * Remove some eslint overrides * Use noop --- packages/api-contract/src/checkTypes.manual.ts | 4 +--- packages/api/src/base/Init.ts | 7 +++---- packages/api/src/checkTypes.manual.ts | 5 +---- packages/api/src/promise/Api.ts | 6 ++---- packages/api/src/promise/Combinator.ts | 10 +++++----- packages/api/src/promise/index.spec.ts | 1 - packages/rpc-core/src/bundle.ts | 1 - packages/rpc-core/src/replay.spec.ts | 6 ++---- .../rpc-provider/src/substrate-connect/index.ts | 6 +++--- packages/rpc-provider/src/ws/index.ts | 14 ++++---------- 10 files changed, 21 insertions(+), 39 deletions(-) diff --git a/packages/api-contract/src/checkTypes.manual.ts b/packages/api-contract/src/checkTypes.manual.ts index 89c63ba0b9..49b28dd8be 100644 --- a/packages/api-contract/src/checkTypes.manual.ts +++ b/packages/api-contract/src/checkTypes.manual.ts @@ -36,12 +36,10 @@ async function main (): Promise { }); const pairs = createTestPairs(); - // eslint-disable-next-line @typescript-eslint/no-floating-promises - Promise.all([ + await Promise.all([ checkBlueprint(api, pairs), checkContract(api, pairs) ]); } -// eslint-disable-next-line @typescript-eslint/unbound-method main().catch(console.error); diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 470db1ec29..e44cab5960 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -15,7 +15,7 @@ import { firstValueFrom, map, of, switchMap } from 'rxjs'; import { Metadata, TypeRegistry } from '@polkadot/types'; import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known'; -import { assertReturn, BN_ZERO, isUndefined, logger, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util'; +import { assertReturn, BN_ZERO, isUndefined, logger, noop, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import { Decorate } from './Decorate.js'; @@ -77,8 +77,7 @@ export abstract class Init extends Decorate { // 'connected' event, then the `on('connected')` won't fire anymore. To // cater for this case, we call manually `this._onProviderConnect`. if (this._rpcCore.provider.isConnected) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.#onProviderConnect(); + this.#onProviderConnect().catch(noop); } } @@ -378,7 +377,7 @@ export abstract class Init extends Decorate { // Only enable the health keepalive on WS, not needed on HTTP this.#healthTimer = this.hasSubscriptions ? setInterval((): void => { - firstValueFrom(this._rpcCore.system.health.raw()).catch(() => undefined); + firstValueFrom(this._rpcCore.system.health.raw()).catch(noop); }, KEEPALIVE_INTERVAL) : null; } diff --git a/packages/api/src/checkTypes.manual.ts b/packages/api/src/checkTypes.manual.ts index ceef40c0b3..d9a031684a 100644 --- a/packages/api/src/checkTypes.manual.ts +++ b/packages/api/src/checkTypes.manual.ts @@ -276,7 +276,6 @@ async function tx (api: ApiPromise, pairs: TestKeyringMapSubstrate): Promise console.log(result)); // it handles enum inputs correctly @@ -305,8 +304,7 @@ async function main (): Promise { const api = await ApiPromise.create(); const pairs = createTestPairs(); - // eslint-disable-next-line @typescript-eslint/no-floating-promises - Promise.all([ + await Promise.all([ calls(api), consts(api), derive(api), @@ -322,5 +320,4 @@ async function main (): Promise { ]); } -// eslint-disable-next-line @typescript-eslint/unbound-method main().catch(console.error); diff --git a/packages/api/src/promise/Api.ts b/packages/api/src/promise/Api.ts index 078cb578b4..39f950705a 100644 --- a/packages/api/src/promise/Api.ts +++ b/packages/api/src/promise/Api.ts @@ -4,7 +4,7 @@ import type { ApiOptions, UnsubscribePromise } from '../types/index.js'; import type { CombinatorCallback, CombinatorFunction } from './Combinator.js'; -import { objectSpread } from '@polkadot/util'; +import { noop, objectSpread } from '@polkadot/util'; import { ApiBase } from '../base/index.js'; import { Combinator } from './Combinator.js'; @@ -156,9 +156,7 @@ export class ApiPromise extends ApiBase<'promise'> { // Swallow any rejections on isReadyOrError // (in Node 15.x this creates issues, when not being looked at) - instance.isReadyOrError.catch(() => { - // ignore - }); + instance.isReadyOrError.catch(noop); return instance.isReady; } diff --git a/packages/api/src/promise/Combinator.ts b/packages/api/src/promise/Combinator.ts index 3e93f98b13..936abbbcff 100644 --- a/packages/api/src/promise/Combinator.ts +++ b/packages/api/src/promise/Combinator.ts @@ -4,7 +4,7 @@ import type { Callback } from '@polkadot/types/types'; import type { UnsubscribePromise } from '../types/index.js'; -import { isFunction } from '@polkadot/util'; +import { isFunction, noop } from '@polkadot/util'; export type CombinatorCallback = Callback; @@ -60,8 +60,9 @@ export class Combinator { } try { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.#callback(this.#results as T); + Promise + .resolve(this.#callback(this.#results as T)) + .catch(noop); } catch { // swallow, we don't want the handler to trip us up } @@ -74,8 +75,7 @@ export class Combinator { this.#isActive = false; - // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.#subscriptions.forEach(async (subscription): Promise => { + this.#subscriptions.map(async (subscription): Promise => { try { const unsubscribe = await subscription; diff --git a/packages/api/src/promise/index.spec.ts b/packages/api/src/promise/index.spec.ts index 3af335a136..73d3454c0c 100644 --- a/packages/api/src/promise/index.spec.ts +++ b/packages/api/src/promise/index.spec.ts @@ -21,7 +21,6 @@ describe('ApiPromise', (): void => { const registry = new TypeRegistry(); const keyring = createTestKeyring({ type: 'ed25519' }); const aliceEd = keyring.addPair( - // eslint-disable-next-line @typescript-eslint/unbound-method createPair({ toSS58: keyring.encodeAddress, type: 'ed25519' }, { publicKey: hexToU8a('0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee'), secretKey: hexToU8a('0xabf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a7690911588dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee') diff --git a/packages/rpc-core/src/bundle.ts b/packages/rpc-core/src/bundle.ts index 06507d549b..b8cab96adc 100644 --- a/packages/rpc-core/src/bundle.ts +++ b/packages/rpc-core/src/bundle.ts @@ -108,7 +108,6 @@ export class RpcCore { * @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket) */ constructor (instanceId: string, registry: Registry, { isPedantic = true, provider, userRpc = {} }: Options) { - // eslint-disable-next-line @typescript-eslint/unbound-method if (!provider || !isFunction(provider.send)) { throw new Error('Expected Provider to API create'); } diff --git a/packages/rpc-core/src/replay.spec.ts b/packages/rpc-core/src/replay.spec.ts index d57e736856..e645121452 100644 --- a/packages/rpc-core/src/replay.spec.ts +++ b/packages/rpc-core/src/replay.spec.ts @@ -26,9 +26,9 @@ describe('replay', (): void => { it('returns the observable value', async (): Promise => { await new Promise((resolve) => { - rpc.system.chain().subscribe((value: any): void => { + rpc.system.chain().subscribe((value?: { toString: () => string }): void => { if (value) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access, jest/no-conditional-expect + // eslint-disable-next-line jest/no-conditional-expect expect(value.toString()).toEqual('mockChain'); // Defined in MockProvider resolve(true); } @@ -56,7 +56,6 @@ describe('replay', (): void => { }); it('unsubscribes as required', async (): Promise => { - // eslint-disable-next-line @typescript-eslint/unbound-method rpc.provider.unsubscribe = jest.fn(); await new Promise((resolve) => { @@ -65,7 +64,6 @@ describe('replay', (): void => { // There's a promise inside .unsubscribe(), wait a bit (> 2s) setTimeout((): void => { - // eslint-disable-next-line @typescript-eslint/unbound-method expect(rpc.provider.unsubscribe).toHaveBeenCalled(); resolve(true); }, 3500); diff --git a/packages/rpc-provider/src/substrate-connect/index.ts b/packages/rpc-provider/src/substrate-connect/index.ts index 945bec9b6a..60fc48cbe0 100644 --- a/packages/rpc-provider/src/substrate-connect/index.ts +++ b/packages/rpc-provider/src/substrate-connect/index.ts @@ -6,7 +6,7 @@ import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, Pro import { EventEmitter } from 'eventemitter3'; -import { isError, isFunction, isObject, logger, objectSpread } from '@polkadot/util'; +import { isError, isFunction, isObject, logger, noop, objectSpread } from '@polkadot/util'; import { RpcCoder } from '../coder/index.js'; import { healthChecker } from './Health.js'; @@ -193,11 +193,11 @@ export class ScProvider implements ProviderInterface { Promise .race([ - this.send(unsubscribeMethod, [id]).catch(() => undefined), + this.send(unsubscribeMethod, [id]).catch(noop), new Promise((resolve) => setTimeout(resolve, 500)) ]) .then(killStaleSubscriptions) - .catch(() => undefined); + .catch(noop); }; hc.start((health) => { diff --git a/packages/rpc-provider/src/ws/index.ts b/packages/rpc-provider/src/ws/index.ts index 8b60b32079..850e52a9d6 100644 --- a/packages/rpc-provider/src/ws/index.ts +++ b/packages/rpc-provider/src/ws/index.ts @@ -6,7 +6,7 @@ import type { EndpointStats, JsonRpcResponse, ProviderInterface, ProviderInterfa import { EventEmitter } from 'eventemitter3'; -import { isChildClass, isNull, isUndefined, logger, objectSpread } from '@polkadot/util'; +import { isChildClass, isNull, isUndefined, logger, noop, objectSpread } from '@polkadot/util'; import { xglobal } from '@polkadot/x-global'; import { WebSocket } from '@polkadot/x-ws'; @@ -138,9 +138,7 @@ export class WsProvider implements ProviderInterface { this.#timeout = timeout || DEFAULT_TIMEOUT_MS; if (autoConnectMs && autoConnectMs > 0) { - this.connectWithRetry().catch((): void => { - // does not throw - }); + this.connectWithRetry().catch(noop); } this.#isReadyPromise = new Promise((resolve): void => { @@ -244,9 +242,7 @@ export class WsProvider implements ProviderInterface { await this.connect(); } catch { setTimeout((): void => { - this.connectWithRetry().catch((): void => { - // does not throw - }); + this.connectWithRetry().catch(noop); }, this.#autoConnectMs); } } @@ -469,9 +465,7 @@ export class WsProvider implements ProviderInterface { if (this.#autoConnectMs > 0) { setTimeout((): void => { - this.connectWithRetry().catch(() => { - // does not throw - }); + this.connectWithRetry().catch(noop); }, this.#autoConnectMs); } };