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
@@ -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'