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
+1 -1
View File
@@ -31,7 +31,7 @@ export default abstract class AbstractInt extends BN implements Codec {
public constructor (
isNegative: boolean,
value: AnyNumber = 0,
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson: boolean = true) {
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson = true) {
super(
AbstractInt.decodeAbstracInt(value, bitLength, isNegative)
);
+1 -1
View File
@@ -120,6 +120,6 @@ export default class Compact<T extends CompactEncodable> extends Base<T> {
* @description Returns the embedded [[UInt]] or [[Moment]] value
*/
public unwrap (): T {
return this.raw as T;
return this.raw;
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ import U64 from '../primitive/U64';
describe('Date', (): void => {
describe('decode', (): void => {
const testDecode = (type: string, input: Date | CodecDate | U64 | number, expected: string | number, toJSON: boolean = false): void =>
const testDecode = (type: string, input: Date | CodecDate | U64 | number, expected: string | number, toJSON = false): void =>
it(`can decode from ${type}`, (): void => {
expect(new CodecDate(input)[toJSON ? 'toJSON' : 'toISOString']()).toBe(expected);
});
+1 -1
View File
@@ -93,7 +93,7 @@ export default class CodecDate extends Date implements Codec {
/**
* @description Returns a hex string representation of the value
*/
public toHex (isLe: boolean = false): string {
public toHex (isLe = false): string {
return bnToHex(this.toBn(), {
bitLength: BITLENGTH,
isLe,
+1 -1
View File
@@ -122,7 +122,7 @@ export default class Enum extends Base<Codec> {
return Enum.createValue(def, index, value);
}
private static createValue (def: TypesDef, index: number = 0, value?: any): Decoded {
private static createValue (def: TypesDef, index = 0, value?: any): Decoded {
const Clazz = Object.values(def)[index];
assert(!isUndefined(Clazz), `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
+2 -2
View File
@@ -21,7 +21,7 @@ import AbstractInt, { DEFAULT_UINT_BITS, UIntBitLength } from './AbstractInt';
export default class Int extends AbstractInt {
public constructor (
value: AnyNumber = 0,
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson: boolean = true) {
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson = true) {
super(
true,
value,
@@ -33,7 +33,7 @@ export default class Int extends AbstractInt {
/**
* @description Returns a hex string representation of the value
*/
public toHex (isLe: boolean = false): string {
public toHex (isLe = false): string {
return bnToHex(this, {
bitLength: this._bitLength,
isLe,
+2 -2
View File
@@ -22,7 +22,7 @@ import AbstractInt, { DEFAULT_UINT_BITS, UIntBitLength } from './AbstractInt';
export default class UInt extends AbstractInt {
public constructor (
value: AnyNumber = 0,
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson: boolean = false) {
bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson = false) {
super(
false,
value,
@@ -34,7 +34,7 @@ export default class UInt extends AbstractInt {
/**
* @description Returns a hex string representation of the value
*/
public toHex (isLe: boolean = false): string {
public toHex (isLe = false): string {
// For display/JSON, this is BE, for compare, use isLe
return bnToHex(this, {
bitLength: this._bitLength,
@@ -95,7 +95,7 @@ function hasWrapper (type: string, [start, end]: [string, string, any]): boolean
return false;
}
assert(type[type.length - 1] === end, `Expected '${start}' closing with '${end}'`);
assert(type.endsWith(end), `Expected '${start}' closing with '${end}'`);
return true;
}
@@ -11,7 +11,7 @@ import { ClassOf } from '../create';
export function typeToConstructor <T = Codec> (type: InterfaceTypes | Constructor<T>): Constructor<T> {
return (
isString(type)
? ClassOf(type as InterfaceTypes)
? ClassOf(type)
: type
) as Constructor<T>;
}
+1 -2
View File
@@ -38,10 +38,9 @@ export default class Bytes extends U8a {
return value;
}
private static decodeBytesStorage (value: Uint8Array): Uint8Array {
private static decodeBytesStorage (u8a: Uint8Array): Uint8Array {
// Here we cater for the actual StorageData that _could_ have a length prefix. In the
// case of `:code` it is not added, for others it is
const u8a = value as Uint8Array;
const [offset, length] = Compact.decodeU8a(u8a);
return u8a.length === length.addn(offset).toNumber()
@@ -241,12 +241,11 @@ export default class Extrinsic extends Base<ExtrinsicVx | ExtrinsicUnknown> impl
// payload: ExtrinsicPayloadValue | Uint8Array | string
let payload = args[0];
// @ts-ignore
if (args.length === 2) {
// FIXME The old support as detailed above... needs to be dropped
if ((args as any[]).length === 2) {
payload = {
blockHash: new Uint8Array(),
// @ts-ignore
era: args[1] as string,
era: (args as any[])[1] as string,
genesisHash: new Uint8Array(),
method: this.method.toHex(),
nonce: args[0] as string,
@@ -32,7 +32,7 @@ export default class ExtrinsicV1 extends Struct implements IExtrinsicImpl {
}, ExtrinsicV1.decodeExtrinsic(value, isSigned));
}
public static decodeExtrinsic (value?: Uint8Array | ExtrinsicValueV1, isSigned: boolean = false): ExtrinsicValueV1 {
public static decodeExtrinsic (value?: Uint8Array | ExtrinsicValueV1, isSigned = false): ExtrinsicValueV1 {
if (!value) {
return {};
} else if (value instanceof ExtrinsicV1) {
@@ -32,7 +32,7 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
}, ExtrinsicSignatureV1.decodeExtrinsicSignature(value, isSigned));
}
public static decodeExtrinsicSignature (value: ExtrinsicSignatureV1 | Uint8Array | undefined, isSigned: boolean = false): ExtrinsicSignatureV1 | Uint8Array {
public static decodeExtrinsicSignature (value: ExtrinsicSignatureV1 | Uint8Array | undefined, isSigned = false): ExtrinsicSignatureV1 | Uint8Array {
if (!value) {
return EMPTY_U8A;
} else if (value instanceof ExtrinsicSignatureV1) {
@@ -32,7 +32,7 @@ export default class ExtrinsicV2 extends Struct implements IExtrinsicImpl {
}, ExtrinsicV2.decodeExtrinsic(value, isSigned));
}
public static decodeExtrinsic (value?: Call | Uint8Array | ExtrinsicValueV2, isSigned: boolean = false): ExtrinsicValueV2 {
public static decodeExtrinsic (value?: Call | Uint8Array | ExtrinsicValueV2, isSigned = false): ExtrinsicValueV2 {
if (!value) {
return {};
} else if (value instanceof ExtrinsicV2) {
@@ -28,7 +28,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
}, ExtrinsicSignatureV2.decodeExtrinsicSignature(value, isSigned));
}
public static decodeExtrinsicSignature (value: ExtrinsicSignatureV2 | Uint8Array | undefined, isSigned: boolean = false): ExtrinsicSignatureV2 | Uint8Array {
public static decodeExtrinsicSignature (value: ExtrinsicSignatureV2 | Uint8Array | undefined, isSigned = false): ExtrinsicSignatureV2 | Uint8Array {
if (!value) {
return EMPTY_U8A;
} else if (value instanceof ExtrinsicSignatureV2) {
@@ -32,7 +32,7 @@ export default class ExtrinsicV3 extends Struct implements IExtrinsicImpl {
}, ExtrinsicV3.decodeExtrinsic(value, isSigned));
}
public static decodeExtrinsic (value?: Call | Uint8Array | ExtrinsicValueV3, isSigned: boolean = false): ExtrinsicValueV3 {
public static decodeExtrinsic (value?: Call | Uint8Array | ExtrinsicValueV3, isSigned = false): ExtrinsicValueV3 {
if (!value) {
return {};
} else if (value instanceof ExtrinsicV3) {
@@ -61,7 +61,7 @@ describe('AccountId', (): void => {
});
describe('encoding', (): void => {
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input: string = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'): void =>
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'): void =>
it(`can encode ${to}`, (): void => {
const a = createType('AccountId', input);
@@ -3,6 +3,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@babel/register')({
extensions: ['.js', '.ts'],
plugins: [
+6 -6
View File
@@ -74,17 +74,17 @@ function isCompactEncodable (Child: Constructor<any>): boolean {
}
// helper to generate a `export interface <Name> extends <Base> {<Body>}
function exportInterface (name: string = '', base: string, body: string = ''): string {
function exportInterface (name = '', base: string, body = ''): string {
return `/** ${base} */\nexport interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`;
}
// helper to create an `export <Name> = <Base>`
function exportType (name: string = '', base: string): string {
function exportType (name = '', base: string): string {
return `/** ${base} */\nexport type ${name} = ${base};`;
}
// helper to generate a `readonly <Name>: <Type>;` getter
function createGetter (name: string = '', type: string, imports: TypeImports, doc?: string): string {
function createGetter (name = '', type: string, imports: TypeImports, doc?: string): string {
setImports(imports, [type]);
return ` /** ${doc || type} */\n readonly ${name}: ${type};\n`;
}
@@ -265,7 +265,7 @@ function createImportCode (header: string, checks: { file: string; types: string
}
// From `T`, generate `Compact<T>, Option<T>, Vec<T>`
function getDerivedTypes (type: string, primitiveName: string, imports: TypeImports, indent: number = 2): string {
function getDerivedTypes (type: string, primitiveName: string, imports: TypeImports, indent = 2): string {
// `primitiveName` represents the actual primitive type our type is mapped to
const isCompact = isCompactEncodable((primitiveClasses as any)[primitiveName]);
@@ -438,8 +438,8 @@ function getSimilarTypes (imports: Imports, type: string): string[] {
return ['any'];
}
// @ts-ignore Cannot get isChildClass of abstract class, but it works
if (isChildClass(AbstractInt, ClassOfUnsafe(type))) {
// Cannot get isChildClass of abstract class, but it works
if (isChildClass(AbstractInt as unknown as Constructor<any>, ClassOfUnsafe(type))) {
possibleTypes.push('Uint8Array', 'number', 'string');
} else if (isChildClass(Uint8Array, ClassOfUnsafe(type))) {
possibleTypes.push('Uint8Array', 'string');
@@ -3,6 +3,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@babel/register')({
extensions: ['.js', '.ts']
});