eslint rules (#1099)

* Off to the races - 3760 problems (1794 errors, 1966 warnings)

* Convert Array<T> -> T[] (not all correct, eg. extends)

* () => { -> (): void  => {

* get is/as -> public get is/as

* public for getters, constructors & base Codec

* Some cleanups from previous overzealous search & replace

* Under 2k, 1874 problems (649 errors, 1225 warnings)

* ^^^ check that commit for details ;)

* Minor.

* rm config header

* Minor cleanups

* Default to tslint, eslint as option

* Trigger

* Update jsonrpc

* 1494 problems (433 errors, 1061 warnings)

* 1103 problems (135 errors, 968 warnings)

* 899 problems (9 errors, 890 warnings)

* 483 problems (9 errors, 474 warnings) (ignore any... for now)

* 366 problems (9 errors, 357 warnings)

* 336 problems (9 errors, 327 warnings)

* 148 problems (9 errors, 139 warnings)

* 31 problems (8 errors, 23 warnings)

* 0, 0
This commit is contained in:
Jaco Greeff
2019-07-14 12:15:14 +02:00
committed by GitHub
parent f770fb973f
commit 71c5920b1f
354 changed files with 3817 additions and 3632 deletions
@@ -5,46 +5,46 @@
import { JsonRpcResponse } from '../types';
import Coder from './';
describe('decodeResponse', () => {
describe('decodeResponse', (): void => {
let coder: Coder;
beforeEach(() => {
beforeEach((): void => {
coder = new Coder();
});
it('expects a non-empty input object', () => {
it('expects a non-empty input object', (): void => {
expect(
() => coder.decodeResponse((undefined as any) as JsonRpcResponse)
(): any => coder.decodeResponse((undefined as any) as JsonRpcResponse)
).toThrow(/Empty response/);
});
it('expects a valid jsonrpc field', () => {
it('expects a valid jsonrpc field', (): void => {
expect(
() => coder.decodeResponse({} as JsonRpcResponse)
(): any => coder.decodeResponse({} as unknown as JsonRpcResponse)
).toThrow(/Invalid jsonrpc/);
});
it('expects a valid id field', () => {
it('expects a valid id field', (): void => {
expect(
() => coder.decodeResponse({ jsonrpc: '2.0' } as JsonRpcResponse)
(): any => coder.decodeResponse({ jsonrpc: '2.0' } as unknown as JsonRpcResponse)
).toThrow(/Invalid id/);
});
it('expects a valid result field', () => {
it('expects a valid result field', (): void => {
expect(
() => coder.decodeResponse({ id: 1, jsonrpc: '2.0' } as JsonRpcResponse)
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0' } as unknown as JsonRpcResponse)
).toThrow(/No result/);
});
it('throws any error found', () => {
it('throws any error found', (): void => {
expect(
() => coder.decodeResponse({ id: 1, jsonrpc: '2.0', error: { code: 123, message: 'test error' } } as JsonRpcResponse)
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0', error: { code: 123, message: 'test error' } } as unknown as JsonRpcResponse)
).toThrow(/123: test error/);
});
it('returns the result', () => {
it('returns the result', (): void => {
expect(
coder.decodeResponse({ id: 1, jsonrpc: '2.0', result: 'some result' } as JsonRpcResponse)
coder.decodeResponse({ id: 1, jsonrpc: '2.0', result: 'some result' } as unknown as JsonRpcResponse)
).toEqual('some result');
});
});
@@ -4,14 +4,14 @@
import Coder from './';
describe('encodeJson', () => {
describe('encodeJson', (): void => {
let coder: Coder;
beforeEach(() => {
beforeEach((): void => {
coder = new Coder();
});
it('encodes a valid JsonRPC JSON string', () => {
it('encodes a valid JsonRPC JSON string', (): void => {
expect(
coder.encodeJson('method', 'params')
).toEqual('{"id":1,"jsonrpc":"2.0","method":"method","params":"params"}');
@@ -4,18 +4,18 @@
import Coder from './';
describe('encodeObject', () => {
describe('encodeObject', (): void => {
let coder: Coder;
beforeEach(() => {
beforeEach((): void => {
coder = new Coder();
});
it('starts with id === 0 (nothing sent)', () => {
it('starts with id === 0 (nothing sent)', (): void => {
expect(coder.getId()).toEqual(0);
});
it('encodes a valid JsonRPC object', () => {
it('encodes a valid JsonRPC object', (): void => {
expect(
coder.encodeObject('method', 'params')
).toEqual({
+7 -7
View File
@@ -2,14 +2,14 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { JsonRpcRequest, JsonRpcResponse, JsonRpcResponseBase$Error } from '../types';
import { JsonRpcRequest, JsonRpcResponse, JsonRpcResponseBaseError } from '../types';
import { assert, isUndefined, isNumber } from '@polkadot/util';
export default class RpcCoder {
private id: number = 0;
decodeResponse (response: JsonRpcResponse): any {
public decodeResponse (response: JsonRpcResponse): any {
assert(response, 'Empty response object received');
assert(response.jsonrpc === '2.0', 'Invalid jsonrpc field in decoded object');
@@ -30,13 +30,13 @@ export default class RpcCoder {
return response.result;
}
encodeJson (method: string, params: any | Array<any>): string {
public encodeJson (method: string, params: any | any[]): string {
return JSON.stringify(
this.encodeObject(method, params)
);
}
encodeObject (method: string, params: any | Array<any>): JsonRpcRequest {
public encodeObject (method: string, params: any | any[]): JsonRpcRequest {
return {
id: ++this.id,
jsonrpc: '2.0',
@@ -45,16 +45,16 @@ export default class RpcCoder {
};
}
getId (): number {
public getId (): number {
return this.id;
}
private checkError (error?: JsonRpcResponseBase$Error): void {
private checkError (error?: JsonRpcResponseBaseError): void {
if (error) {
const { code, data, message } = error;
const _data = isUndefined(data)
? ''
: ' (' + `${data}`.substr(0, 10) + ')' ;
: ' (' + `${data}`.substr(0, 10) + ')';
console.error(`${code}: ${message}${_data}`);