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
+7 -7
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { CodecArg, Constructor } from '@polkadot/types/types';
import { ContractABIFn, ContractABIFn$Arg, ContractABIMethod, ContractABIMethodBase, ContractABITypes } from './types';
import { ContractABIFn, ContractABIArg, ContractABIMethod, ContractABIMethodBase, ContractABITypes } from './types';
import { Compact, createClass } from '@polkadot/types';
import { assert, isString, isUndefined, stringCamelCase } from '@polkadot/util';
@@ -12,7 +12,7 @@ export function typeToString (type: ContractABITypes): string {
if (isString(type)) {
return type;
} else if (Array.isArray(type)) {
return `(${type.map((type) => typeToString(type)).join(',')})`;
return `(${type.map((type): string => typeToString(type)).join(',')})`;
} else if (type['Option<T>']) {
return `Option<${typeToString(type['Option<T>'].T)}>`;
} else if (type['Result<T,E>']) {
@@ -26,10 +26,10 @@ export function typeToString (type: ContractABITypes): string {
throw new Error(`Unknown type specified ${JSON.stringify(type)}`);
}
export function createArgClass (args: Array<ContractABIFn$Arg>, baseDef: { [index: string]: string }): Constructor {
export function createArgClass (args: ContractABIArg[], baseDef: Record<string, string>): Constructor {
return createClass(
JSON.stringify(
args.reduce((base: { [index: string]: string }, { name, type }) => {
args.reduce((base: Record<string, any>, { name, type }): Record<string, any> => {
base[name] = type;
return base;
@@ -39,17 +39,17 @@ export function createArgClass (args: Array<ContractABIFn$Arg>, baseDef: { [inde
}
export function createMethod (name: string, method: Partial<ContractABIMethod> & ContractABIMethodBase): ContractABIFn {
const args: Array<ContractABIFn$Arg> = method.args.map(({ name, type }) => ({
const args: ContractABIArg[] = method.args.map(({ name, type }): ContractABIArg => ({
name: stringCamelCase(name),
type: typeToString(type)
}));
const Clazz = createArgClass(args, isUndefined(method.selector) ? {} : { __selector: 'u32' });
const baseStruct: { [index: string]: any } = { __selector: method.selector };
const encoder = (...params: Array<CodecArg>): Uint8Array => {
const encoder = (...params: CodecArg[]): Uint8Array => {
assert(params.length === args.length, `Expected ${args.length} arguments to contract ${name}, found ${params.length}`);
const u8a = new Clazz(
args.reduce((mapped, { name }, index) => {
args.reduce((mapped, { name }, index): Record<string, CodecArg> => {
mapped[name] = params[index];
return mapped;