Typescript-eslint 2 (#1353)

* Make a start

* More minor cleanups

* Some more cleanups

* Last round?

* Exclude build folders
This commit is contained in:
Jaco Greeff
2019-09-02 07:01:32 +02:00
committed by GitHub
parent bd5c167c14
commit 2dd7cc0e69
94 changed files with 391 additions and 324 deletions
+2 -2
View File
@@ -63,8 +63,8 @@ describe('Cached Observables', (): void => {
});
it('creates different observables for different methods but same arguments', (): void => {
// @ts-ignore
const observable1 = rpc.chain.subscribeNewHeads([123]);
// params do not match here
const observable1 = (rpc.chain as any).subscribeNewHeads([123]);
const observable2 = rpc.state.subscribeStorage([123]);
expect(observable2).not.toBe(observable1);
+2
View File
@@ -70,6 +70,7 @@ export default class Rpc implements RpcInterface {
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
*/
public constructor (provider: ProviderInterface) {
// eslint-disable-next-line @typescript-eslint/unbound-method
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
this.provider = provider;
@@ -249,6 +250,7 @@ export default class Rpc implements RpcInterface {
// Normalize args so that different args that should be cached
// together are cached together.
// E.g.: `query.my.method('abc') === query.my.method(createType('AccountId', 'abc'));`
// eslint-disable-next-line @typescript-eslint/unbound-method
normalizer: JSON.stringify
});
+10 -10
View File
@@ -37,12 +37,12 @@ describe('methodSend', (): void => {
});
it('wraps errors with the call signature', (done): void => {
// @ts-ignore private method
const method = rpc.createMethodSend(methods.blah);
// private access
const method = (rpc as any).createMethodSend(methods.blah);
method().subscribe(
(): void => { /* noop */ },
(error): void => {
(): void => {},
(error: Error): void => {
expect(error.message).toMatch(/blah \(foo: Bytes\): Bytes/);
done();
}
@@ -50,20 +50,20 @@ describe('methodSend', (): void => {
});
it('checks for mismatched parameters', (done): void => {
// @ts-ignore private method
const method = rpc.createMethodSend(methods.bleh);
// private method
const method = (rpc as any).createMethodSend(methods.bleh);
method(1).subscribe(
(): void => { /* noop */ },
(error): void => {
(): void => {},
(error: Error): void => {
expect(error.message).toMatch(/parameters, 1 found instead/);
done();
});
});
it('calls the provider with the correct parameters', (done): void => {
// @ts-ignore private method
const method = rpc.createMethodSend(methods.blah);
// private method
const method = (rpc as any).createMethodSend(methods.blah);
// Args are length-prefixed, because it's a Bytes
method(new Uint8Array([2 << 2, 0x12, 0x34])).subscribe((): void => {
+6 -5
View File
@@ -15,12 +15,11 @@ describe('replay', (): void => {
});
it('subscribes via the rpc section', (done): void => {
// @ts-ignore
rpc.chain.getBlockHash = jest.fn((): Observable<number> => of(1));
// @ts-ignore
rpc.chain.getBlockHash(123, false).subscribe((): void => {
// we don't honor types or number of params here
(rpc.chain as any).getBlockHash = jest.fn((): Observable<number> => of(1));
(rpc.chain as any).getBlockHash(123, false).subscribe((): void => {
expect(
// eslint-disable-next-line @typescript-eslint/unbound-method
rpc.chain.getBlockHash
).toHaveBeenCalledWith(123, false);
@@ -52,6 +51,7 @@ describe('replay', (): void => {
});
it('unsubscribes as required', (done): void => {
// eslint-disable-next-line @typescript-eslint/unbound-method
rpc.provider.unsubscribe = jest.fn();
const subscription = rpc.chain.subscribeNewHeads().subscribe((): void => {
@@ -59,6 +59,7 @@ describe('replay', (): void => {
// There's a promise inside .unsubscribe(), wait a bit
setTimeout((): void => {
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(rpc.provider.unsubscribe).toHaveBeenCalled();
done();
}, 200);