Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some eslint overrides #5676

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/api-contract/src/checkTypes.manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ async function main (): Promise<void> {
});
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);
7 changes: 3 additions & 4 deletions packages/api/src/base/Init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -77,8 +77,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
// '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);
}
}

Expand Down Expand Up @@ -378,7 +377,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
// 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;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/api/src/checkTypes.manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ async function tx (api: ApiPromise, pairs: TestKeyringMapSubstrate): Promise<voi
// it allows for query & then using the submittable
const second = api.tx.democracy.second(123);

// eslint-disable-next-line @typescript-eslint/no-floating-promises
await second.signAndSend('123', (result) => console.log(result));

// it handles enum inputs correctly
Expand Down Expand Up @@ -305,8 +304,7 @@ async function main (): Promise<void> {
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),
Expand All @@ -322,5 +320,4 @@ async function main (): Promise<void> {
]);
}

// eslint-disable-next-line @typescript-eslint/unbound-method
main().catch(console.error);
6 changes: 2 additions & 4 deletions packages/api/src/promise/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/promise/Combinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends unknown[]> = Callback<T>;

Expand Down Expand Up @@ -60,8 +60,9 @@ export class Combinator<T extends unknown[] = unknown[]> {
}

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
}
Expand All @@ -74,8 +75,7 @@ export class Combinator<T extends unknown[] = unknown[]> {

this.#isActive = false;

// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.#subscriptions.forEach(async (subscription): Promise<void> => {
this.#subscriptions.map(async (subscription): Promise<void> => {
try {
const unsubscribe = await subscription;

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/promise/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion packages/rpc-core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
6 changes: 2 additions & 4 deletions packages/rpc-core/src/replay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('replay', (): void => {

it('returns the observable value', async (): Promise<void> => {
await new Promise<boolean>((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);
}
Expand Down Expand Up @@ -56,7 +56,6 @@ describe('replay', (): void => {
});

it('unsubscribes as required', async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/unbound-method
rpc.provider.unsubscribe = jest.fn();

await new Promise<boolean>((resolve) => {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/rpc-provider/src/substrate-connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down
14 changes: 4 additions & 10 deletions packages/rpc-provider/src/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
};
Expand Down