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
@@ -11,8 +11,8 @@ import fromMetadata from '../fromMetadata';
const metadata = new Metadata(json);
const consts = fromMetadata(metadata);
describe('fromMetadata', () => {
it('should return constants with the correct type and value', () => {
describe('fromMetadata', (): void => {
it('should return constants with the correct type and value', (): void => {
expect(consts.democracy.cooloffPeriod).toBeInstanceOf(BlockNumber);
expect(consts.democracy.cooloffPeriod.eq(432000)).toBeTruthy();
});
@@ -14,7 +14,7 @@ import { Constants, ModuleConstants } from './types';
* @param metadata - The metadata
*/
export default function fromMetadata (metadata: Metadata): Constants {
return metadata.asV6.modules.reduce((result, moduleMetadata) => {
return metadata.asV6.modules.reduce((result, moduleMetadata): Constants => {
if (moduleMetadata.constants.isEmpty) {
return result;
}
@@ -22,11 +22,11 @@ export default function fromMetadata (metadata: Metadata): Constants {
const { name } = moduleMetadata;
// For access, we change the index names, i.e. Democracy.EnactmentPeriod -> democracy.enactmentPeriod
result[stringCamelCase(name.toString())] = moduleMetadata.constants.reduce((newModule, constantMeta) => {
result[stringCamelCase(name.toString())] = moduleMetadata.constants.reduce((newModule, constantMeta): ModuleConstants => {
newModule[stringCamelCase(constantMeta.name.toString())] = createType(constantMeta.type, constantMeta.value);
return newModule;
}, {} as ModuleConstants);
}, {} as unknown as ModuleConstants);
return result;
}, { } as Constants);
}, {} as unknown as Constants);
}
@@ -11,16 +11,16 @@ import fromV6 from '.';
const metadata = new Metadata(json);
const newExtrinsics = fromV6(metadata);
describe('fromMetadata', () => {
it('should throw if an incorrect number of args is supplied', () => {
expect(() => newExtrinsics.balances.setBalance()).toThrowError(/expects 3 arguments/);
describe('fromMetadata', (): void => {
it('should throw if an incorrect number of args is supplied', (): void => {
expect((): any => newExtrinsics.balances.setBalance()).toThrowError(/expects 3 arguments/);
});
it('should return a value if the storage function does not expect an argument', () => {
expect(() => newExtrinsics.balances.setBalance('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', 2, 3)).not.toThrow();
it('should return a value if the storage function does not expect an argument', (): void => {
expect((): any => newExtrinsics.balances.setBalance('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', 2, 3)).not.toThrow();
});
it('should return properly-encoded transactions', () => {
it('should return properly-encoded transactions', (): void => {
expect(
new Extrinsic(newExtrinsics.timestamp.set([10101])).toU8a()
).toEqual(
@@ -17,17 +17,17 @@ import createUnchecked from './createUnchecked';
*/
export default function fromMetadata (metadata: Metadata): ModulesWithMethods {
return metadata.asV6.modules
.filter((modul) => modul.calls.isSome)
.reduce((result, modul: ModuleMetadata, sectionIndex) => {
.filter((modul): boolean => modul.calls.isSome)
.reduce((result, modul: ModuleMetadata, sectionIndex): ModulesWithMethods => {
const section = stringCamelCase(modul.name.toString());
result[section] = modul.calls.unwrap().reduce((newModule, callMetadata, methodIndex) => {
result[section] = modul.calls.unwrap().reduce((newModule, callMetadata, methodIndex): Methods => {
const method = stringCamelCase(callMetadata.name.toString());
newModule[method] = createUnchecked(section, sectionIndex, methodIndex, callMetadata);
return newModule;
}, {} as Methods);
}, {} as unknown as Methods);
return result;
}, { ...extrinsics });
@@ -9,8 +9,8 @@ import extrinsics from './static';
const keyring = testingPairs({ type: 'ed25519' }, false);
describe('extrinsics', () => {
it('encodes extrinsic correctly (nobody)', () => {
describe('extrinsics', (): void => {
it('encodes extrinsic correctly (nobody)', (): void => {
expect(
new Extrinsic(
extrinsics.timestamp.set(10101)
@@ -26,7 +26,7 @@ describe('extrinsics', () => {
]));
});
it('encodes an actual transfer (actual data)', () => {
it('encodes an actual transfer (actual data)', (): void => {
expect(
new Extrinsic(
extrinsics.balances.transfer(keyring.bob.publicKey, 6969)
@@ -14,28 +14,28 @@ const keyring = testingPairs({ type: 'ed25519' });
// @TODO 1: All three tests below are broken, fix or find better way to test transfers.
// @TODO 2: Move tests out of ./type-metadata to ./api folder
describe.skip('e2e transfer', () => {
describe.skip('e2e transfer', (): void => {
let api: RpcInterface;
beforeAll(() => {
beforeAll((): void => {
api = new Rpc(new WsProvider('ws://127.0.0.1:9944'));
});
beforeEach(() => {
beforeEach((): void => {
jest.setTimeout(30000);
});
// Error: [1002]: Inherent transactions cannot be queued.
it('inherent test', (done) => {
it('inherent test', (done): void => {
const inherent = extrinsics.timestamp.set(Math.round(Date.now() / 1000));
api.author.submitExtrinsic(inherent.toU8a()).subscribe(done);
});
it('makes a transfer for a transaction', (done) => {
it('makes a transfer for a transaction', (done): void => {
api.chain
.getBlockHash(0)
.subscribe((genesisHash) => {
.subscribe((genesisHash): void => {
const extrinsic = extrinsics.balances.transfer(keyring.bob.publicKey, 6969) as any;
extrinsic.sign(keyring.alice, { blockHash: genesisHash, nonce: 0 });
@@ -43,14 +43,14 @@ describe.skip('e2e transfer', () => {
});
});
it('makes a transfer via watch', (done) => {
it('makes a transfer via watch', (done): void => {
api.chain
.getBlockHash(0)
.subscribe((genesisHash) => {
.subscribe((genesisHash): void => {
const extrinsic = extrinsics.balances.transfer(keyring.bob.publicKey, 6969) as any;
extrinsic.sign(keyring.alice, { blockHash: genesisHash, nonce: 0 });
api.author.submitAndWatchExtrinsic(extrinsic).subscribe((result: SubmittableResult) => {
api.author.submitAndWatchExtrinsic(extrinsic).subscribe((result: SubmittableResult): void => {
if (result.status.isFinalized) {
done();
}
@@ -8,8 +8,8 @@ import { stringToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
import createFunction from './createFunction';
describe('createFunction', () => {
it('should create timestamp.now correctly', () => {
describe('createFunction', (): void => {
it('should create timestamp.now correctly', (): void => {
expect(
createFunction({
prefix: 'Timestamp',
@@ -22,7 +22,7 @@ describe('createFunction', () => {
);
});
it('allows overrides on key (keeping name)', () => {
it('allows overrides on key (keeping name)', (): void => {
expect(
createFunction(
{
@@ -39,7 +39,7 @@ describe('createFunction', () => {
).toEqual('authorityCount');
});
it('allows overrides on key (unhashed)', () => {
it('allows overrides on key (unhashed)', (): void => {
const key = ':auth:len';
expect(
@@ -63,9 +63,10 @@ describe('createFunction', () => {
);
});
describe('the created double map function', () => {
describe('the created double map function', (): void => {
let storageFn: StorageEntry;
beforeAll(() => {
beforeAll((): void => {
storageFn = createFunction({
prefix: 'GenericAsset',
section: 'genericAsset',
@@ -86,19 +87,19 @@ describe('createFunction', () => {
});
});
it('should return correct key', () => {
it('should return correct key', (): void => {
const result = storageFn(['5DXUeE5N5LtkW97F2PzqYPyqNkxqSWESdGSPTX6AvkUAhwKP', '5DXUeE5N5LtkW97F2PzqYPyqNkxqSWESdGSPTX6AvkUAhwKP']);
expect(u8aToHex(result)).toEqual('0xc000fa40e72d7173e69ee54b980345ea01cb81e64258502e0247af4303dee91ec0aec2ecd3a60ab080cff7b52a8f6d543b');
});
it('needs two arguments', () => {
it('needs two arguments', (): void => {
expect(
() => storageFn(['5DXUeE5N5LtkW97F2PzqYPyqNkxqSWESdGSPTX6AvkUAhwKP'])
(): Uint8Array => storageFn(['5DXUeE5N5LtkW97F2PzqYPyqNkxqSWESdGSPTX6AvkUAhwKP'])
).toThrow(/metaName expects two arguments/);
});
});
it('allows creates double map function with a Null type key', () => {
it('allows creates double map function with a Null type key', (): void => {
const storageFn = createFunction({
prefix: 'System',
section: 'system',
@@ -89,7 +89,7 @@ export default function createFunction ({ meta, method, prefix, section }: Creat
if (meta.type.isMap && meta.type.asMap.isLinked) {
const keyHash = new U8a(hasher(`head of ${stringKey}`));
const keyFn: any = () => keyHash;
const keyFn: any = (): U8a => keyHash;
keyFn.meta = new StorageEntryMetadata({
name: meta.name,
modifier: new StorageEntryModifier('Required'),
@@ -14,16 +14,16 @@ const keyring = testingPairs({ type: 'ed25519' });
const metadata = new Metadata(json);
const storage = fromMetadata(metadata);
describe('fromMetadata', () => {
it('should throw if the storage function expects an argument', () => {
expect(() => storage.balances.freeBalance()).toThrowError(/expects one argument/);
describe('fromMetadata', (): void => {
it('should throw if the storage function expects an argument', (): void => {
expect((): any => storage.balances.freeBalance()).toThrowError(/expects one argument/);
});
it('should return a value if the storage function does not expect an argument', () => {
expect(() => storage.timestamp.now()).not.toThrow();
it('should return a value if the storage function does not expect an argument', (): void => {
expect((): any => storage.timestamp.now()).not.toThrow();
});
it('should return the correct length-prefixed storage key', () => {
it('should return the correct length-prefixed storage key', (): void => {
expect(
u8aToHex(
storage.balances.freeBalance(keyring.alice.address)
@@ -12,28 +12,28 @@ export type HasherFunction = (data: HasherInput) => Uint8Array;
export default function getHasher (hasher?: StorageHasher): HasherFunction {
// This one is the default for PlainType storage keys
if (!hasher) {
return (data: HasherInput) => xxhashAsU8a(data, 128);
return (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128);
}
if (hasher.isBlake2128) {
return (data: HasherInput) => blake2AsU8a(data, 128);
return (data: HasherInput): Uint8Array => blake2AsU8a(data, 128);
}
if (hasher.isBlake2256) {
return (data: HasherInput) => blake2AsU8a(data, 256);
return (data: HasherInput): Uint8Array => blake2AsU8a(data, 256);
}
if (hasher.isTwox128) {
return (data: HasherInput) => xxhashAsU8a(data, 128);
return (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128);
}
if (hasher.isTwox256) {
return (data: HasherInput) => xxhashAsU8a(data, 256);
return (data: HasherInput): Uint8Array => xxhashAsU8a(data, 256);
}
// FIXME Add Twox128Concat
// All cases should be handled above, but if not, return Twox128 for
// backwards-compatbility
return (data: HasherInput) => xxhashAsU8a(data, 128);
return (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128);
}
@@ -16,7 +16,7 @@ import { storage } from './storage';
* @param metadata - The metadata
*/
export default function fromMetadata (metadata: Metadata): Storage {
return metadata.asV6.modules.reduce((result, moduleMetadata) => {
return metadata.asV6.modules.reduce((result, moduleMetadata): Storage => {
if (moduleMetadata.storage.isNone) {
return result;
}
@@ -25,7 +25,7 @@ export default function fromMetadata (metadata: Metadata): Storage {
const section = stringCamelCase(name.toString());
// For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance
result[section] = moduleMetadata.storage.unwrap().reduce((newModule, meta) => {
result[section] = moduleMetadata.storage.unwrap().reduce((newModule, meta): ModuleStorage => {
const method = meta.name.toString();
newModule[stringLowerFirst(method)] = createFunction({
@@ -36,7 +36,7 @@ export default function fromMetadata (metadata: Metadata): Storage {
});
return newModule;
}, {} as ModuleStorage);
}, {} as unknown as ModuleStorage);
return result;
}, { ...storage });
@@ -4,8 +4,8 @@
import { storage } from './storage';
describe('storage', () => {
it('should return well known keys', () => {
describe('storage', (): void => {
it('should return well known keys', (): void => {
expect(typeof storage.substrate).toBe('object');
// @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys
@@ -4,37 +4,36 @@
import { authorityCount, authorityPrefix, changesTrieConfig, childStorageKeyPrefix, code, extrinsicIndex, heapPages } from './substrate';
describe('substrate', () => {
describe('substrate', (): void => {
// @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys
// have been removed in https://github.com/paritytech/substrate/pull/2802
it('authorityCount should return the correct storage key', () => {
it('authorityCount should return the correct storage key', (): void => {
expect(authorityCount()).toEqual(Uint8Array.from([36, 58, 97, 117, 116, 104, 58, 108, 101, 110])); // Length-prefixed
});
it('authorityPrefix should return the correct storage key', () => {
it('authorityPrefix should return the correct storage key', (): void => {
expect(authorityPrefix()).toEqual(Uint8Array.from([24, 58, 97, 117, 116, 104, 58])); // Length-prefixed
});
it('changesTrieConfig should return the correct storage key', () => {
it('changesTrieConfig should return the correct storage key', (): void => {
expect(changesTrieConfig()).toEqual(Uint8Array.from([52, 58, 99, 104, 97, 110, 103, 101, 115, 95, 116, 114, 105, 101])); // Length-prefixed
});
it('childStorageKeyPrefix should return the correct storage key', () => {
expect(childStorageKeyPrefix()).toEqual(Uint8Array.from([ 60, 58, 99, 104, 105, 108, 100, 95, 115, 116, 111, 114, 97, 103, 101, 58])); // Length-prefixed
it('childStorageKeyPrefix should return the correct storage key', (): void => {
expect(childStorageKeyPrefix()).toEqual(Uint8Array.from([60, 58, 99, 104, 105, 108, 100, 95, 115, 116, 111, 114, 97, 103, 101, 58])); // Length-prefixed
});
it('code should return the correct storage key', () => {
it('code should return the correct storage key', (): void => {
expect(code()).toEqual(Uint8Array.from([20, 58, 99, 111, 100, 101])); // Length-prefixed
});
it('extrinsicIndex should return the correct storage key', () => {
it('extrinsicIndex should return the correct storage key', (): void => {
expect(extrinsicIndex()).toEqual(
Uint8Array.from([64, 58, 101, 120, 116, 114, 105, 110, 115, 105, 99, 95, 105, 110, 100, 101, 120]) // Length-prefixed
);
});
it('heapPages should return the correct storage key', () => {
it('heapPages should return the correct storage key', (): void => {
expect(heapPages()).toEqual(Uint8Array.from([40, 58, 104, 101, 97, 112, 112, 97, 103, 101, 115])); // Length-prefixed
});
});
@@ -22,7 +22,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ
modifier: new StorageEntryModifier(1), // default
type: new StorageEntryType(type, 0),
toJSON: (): any => key
} as StorageEntryMetadata,
} as unknown as StorageEntryMetadata,
method,
prefix: 'Substrate',
section: 'substrate'