Merge pull request #282 from CosmWasm/lint-array-type

Add array-type linter configuration
This commit is contained in:
Simon Warta 2020-07-07 17:52:38 +02:00 committed by GitHub
commit c7f33f4871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 46 additions and 45 deletions

View File

@ -27,10 +27,11 @@ module.exports = {
"no-shadow": "warn",
"no-unused-vars": "off", // disabled in favour of @typescript-eslint/no-unused-vars, see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
"prefer-const": "warn",
"radix": ["warn", "always"],
radix: ["warn", "always"],
"spaced-comment": ["warn", "always", { line: { markers: ["/ <reference"] } }],
"import/no-cycle": "warn",
"simple-import-sort/sort": "warn",
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
"@typescript-eslint/await-thenable": "warn",
"@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true }],
"@typescript-eslint/no-dynamic-delete": "warn",

View File

@ -23,7 +23,7 @@ export interface GetNonceResult {
export interface Account {
/** Bech32 account address */
readonly address: string;
readonly balance: ReadonlyArray<Coin>;
readonly balance: readonly Coin[];
readonly pubkey: PubKey | undefined;
readonly accountNumber: number;
readonly sequence: number;
@ -68,7 +68,7 @@ export interface SearchBySentFromOrToQuery {
* more powerful and slightly lower level than the other search options.
*/
export interface SearchByTagsQuery {
readonly tags: readonly { readonly key: string; readonly value: string }[];
readonly tags: ReadonlyArray<{ readonly key: string; readonly value: string }>;
}
export type SearchTxQuery =
@ -144,7 +144,7 @@ export interface Block {
readonly id: string;
readonly header: BlockHeader;
/** Array of raw transactions */
readonly txs: ReadonlyArray<Uint8Array>;
readonly txs: readonly Uint8Array[];
}
/** Use for testing only */

View File

@ -41,7 +41,7 @@ export interface MsgInstantiateContract extends Msg {
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
readonly init_funds: readonly Coin[];
/** Bech32-encoded admin address */
readonly admin?: string;
};
@ -106,7 +106,7 @@ export interface MsgExecuteContract extends Msg {
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
readonly sent_funds: readonly Coin[];
};
}

View File

@ -55,9 +55,9 @@ interface SmartQueryResponse {
}
/** Unfortunately, Cosmos SDK encodes empty arrays as null */
type CosmosSdkArray<T> = ReadonlyArray<T> | null;
type CosmosSdkArray<T> = readonly T[] | null;
function normalizeArray<T>(backend: CosmosSdkArray<T>): ReadonlyArray<T> {
function normalizeArray<T>(backend: CosmosSdkArray<T>): readonly T[] {
return backend || [];
}

View File

@ -9,7 +9,7 @@ export interface GetNonceResult {
export interface Account {
/** Bech32 account address */
readonly address: string;
readonly balance: ReadonlyArray<Coin>;
readonly balance: readonly Coin[];
readonly pubkey: PubKey | undefined;
readonly accountNumber: number;
readonly sequence: number;
@ -44,10 +44,10 @@ export interface SearchBySentFromOrToQuery {
* more powerful and slightly lower level than the other search options.
*/
export interface SearchByTagsQuery {
readonly tags: readonly {
readonly tags: ReadonlyArray<{
readonly key: string;
readonly value: string;
}[];
}>;
}
export declare type SearchTxQuery =
| SearchByIdQuery
@ -99,7 +99,7 @@ export interface Block {
readonly id: string;
readonly header: BlockHeader;
/** Array of raw transactions */
readonly txs: ReadonlyArray<Uint8Array>;
readonly txs: readonly Uint8Array[];
}
/** Use for testing only */
export interface PrivateCosmWasmClient {

View File

@ -36,7 +36,7 @@ export interface MsgInstantiateContract extends Msg {
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
readonly init_funds: readonly Coin[];
/** Bech32-encoded admin address */
readonly admin?: string;
};
@ -89,7 +89,7 @@ export interface MsgExecuteContract extends Msg {
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
readonly sent_funds: readonly Coin[];
};
}
export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract;

View File

@ -194,11 +194,11 @@ describe("Secp256k1", () => {
it("verifies unnormalized pyca/cryptography signatures", async () => {
// signatures are mixed lowS and non-lowS, prehash type is sha256
const data: readonly {
const data: ReadonlyArray<{
readonly message: Uint8Array;
readonly privkey: Uint8Array;
readonly signature: Uint8Array;
}[] = [
}> = [
{
message: fromHex(
"5c868fedb8026979ebd26f1ba07c27eedf4ff6d10443505a96ecaf21ba8c4f0937b3cd23ffdc3dd429d4cd1905fb8dbcceeff1350020e18b58d2ba70887baa3a9b783ad30d3fbf210331cdd7df8d77defa398cdacdfc2e359c7ba4cae46bb74401deb417f8b912a1aa966aeeba9c39c7dd22479ae2b30719dca2f2206c5eb4b7",
@ -395,11 +395,11 @@ describe("Secp256k1", () => {
it("matches normalized pyca/cryptography signatures", async () => {
// signatures are normalized to lowS, prehash type is sha256
const data: readonly {
const data: ReadonlyArray<{
readonly message: Uint8Array;
readonly privkey: Uint8Array;
readonly signature: Uint8Array;
}[] = [
}> = [
{
message: fromHex(
"5c868fedb8026979ebd26f1ba07c27eedf4ff6d10443505a96ecaf21ba8c4f0937b3cd23ffdc3dd429d4cd1905fb8dbcceeff1350020e18b58d2ba70887baa3a9b783ad30d3fbf210331cdd7df8d77defa398cdacdfc2e359c7ba4cae46bb74401deb417f8b912a1aa966aeeba9c39c7dd22479ae2b30719dca2f2206c5eb4b7",

View File

@ -3,7 +3,7 @@ import { Bip39, Random } from "@cosmjs/crypto";
import * as constants from "../constants";
import { createPens } from "../profile";
export async function generate(args: ReadonlyArray<string>): Promise<void> {
export async function generate(args: readonly string[]): Promise<void> {
if (args.length < 1) {
throw Error(
`Not enough arguments for action 'generate'. See '${constants.binaryName} help' or README for arguments.`,

View File

@ -5,7 +5,7 @@ import * as constants from "../../constants";
import { logAccountsState } from "../../debugging";
import { Faucet } from "../../faucet";
export async function start(args: ReadonlyArray<string>): Promise<void> {
export async function start(args: readonly string[]): Promise<void> {
if (args.length < 1) {
throw Error(
`Not enough arguments for action 'start'. See '${constants.binaryName} help' or README for arguments.`,

View File

@ -1,6 +1,6 @@
import { generate, help, start, version } from "./actions";
export function main(args: ReadonlyArray<string>): void {
export function main(args: readonly string[]): void {
if (args.length < 1) {
help();
process.exit(1);

View File

@ -21,7 +21,7 @@ export function debugAccount(account: MinimalAccount, tokens: TokenConfiguration
return `${account.address}: ${debugBalance(account.balance, tokens)}`;
}
export function logAccountsState(accounts: ReadonlyArray<MinimalAccount>, tokens: TokenConfiguration): void {
export function logAccountsState(accounts: readonly MinimalAccount[], tokens: TokenConfiguration): void {
if (accounts.length < 2) {
throw new Error("List of accounts must contain at least one token holder and one distributor");
}

View File

@ -38,7 +38,7 @@ export class Faucet {
apiUrl: string,
addressPrefix: string,
config: TokenConfiguration,
pens: readonly [string, Pen][],
pens: ReadonlyArray<readonly [string, Pen]>,
logging = false,
) {
this.addressPrefix = addressPrefix;
@ -64,7 +64,7 @@ export class Faucet {
/**
* Returns a list of ticker symbols of tokens owned by the the holder and configured in the faucet
*/
public async availableTokens(): Promise<ReadonlyArray<string>> {
public async availableTokens(): Promise<readonly string[]> {
const holderAccount = await this.readOnlyClient.getAccount(this.holderAddress);
const balance = holderAccount ? holderAccount.balance : [];
@ -99,7 +99,7 @@ export class Faucet {
return this.tokenConfig.bankTokens.map((token) => token.tickerSymbol);
}
public async loadAccounts(): Promise<ReadonlyArray<MinimalAccount>> {
public async loadAccounts(): Promise<readonly MinimalAccount[]> {
const addresses = [this.holderAddress, ...this.distributorAddresses];
return Promise.all(

View File

@ -6,8 +6,8 @@ export async function createPens(
addressPrefix: string,
numberOfDistributors: number,
logging = false,
): Promise<readonly [string, Pen][]> {
const pens = new Array<[string, Pen]>();
): Promise<ReadonlyArray<readonly [string, Pen]>> {
const pens = new Array<readonly [string, Pen]>();
// first account is the token holder
const numberOfIdentities = 1 + numberOfDistributors;

View File

@ -26,7 +26,7 @@ export interface BankTokenMeta {
export interface TokenConfiguration {
/** Supported tokens of the Cosmos SDK bank module */
readonly bankTokens: ReadonlyArray<BankTokenMeta>;
readonly bankTokens: readonly BankTokenMeta[];
}
export type MinimalAccount = Pick<Account, "address" | "balance">;

View File

@ -16,7 +16,7 @@ export interface GetNonceResult {
export interface Account {
/** Bech32 account address */
readonly address: string;
readonly balance: ReadonlyArray<Coin>;
readonly balance: readonly Coin[];
readonly pubkey: PubKey | undefined;
readonly accountNumber: number;
readonly sequence: number;
@ -61,7 +61,7 @@ export interface SearchBySentFromOrToQuery {
* more powerful and slightly lower level than the other search options.
*/
export interface SearchByTagsQuery {
readonly tags: readonly { readonly key: string; readonly value: string }[];
readonly tags: ReadonlyArray<{ readonly key: string; readonly value: string }>;
}
export type SearchTxQuery =
@ -125,7 +125,7 @@ export interface Block {
readonly id: string;
readonly header: BlockHeader;
/** Array of raw transactions */
readonly txs: ReadonlyArray<Uint8Array>;
readonly txs: readonly Uint8Array[];
}
/** Use for testing only */

View File

@ -13,7 +13,7 @@ export interface MsgSend extends Msg {
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
readonly amount: readonly Coin[];
};
}

View File

@ -7,7 +7,7 @@ import { CosmosSdkTx, StdTx } from "./types";
export interface CosmosSdkAccount {
/** Bech32 account address */
readonly address: string;
readonly coins: ReadonlyArray<Coin>;
readonly coins: readonly Coin[];
/** Bech32 encoded pubkey */
readonly public_key: string;
readonly account_number: number;
@ -84,7 +84,7 @@ interface Block {
readonly header: BlockHeader;
readonly data: {
/** Array of base64 encoded transactions */
readonly txs: ReadonlyArray<string> | null;
readonly txs: readonly string[] | null;
};
}

View File

@ -26,7 +26,7 @@ export interface CosmosSdkTx {
}
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly amount: readonly Coin[];
readonly gas: string;
}

View File

@ -9,7 +9,7 @@ export interface GetNonceResult {
export interface Account {
/** Bech32 account address */
readonly address: string;
readonly balance: ReadonlyArray<Coin>;
readonly balance: readonly Coin[];
readonly pubkey: PubKey | undefined;
readonly accountNumber: number;
readonly sequence: number;
@ -44,10 +44,10 @@ export interface SearchBySentFromOrToQuery {
* more powerful and slightly lower level than the other search options.
*/
export interface SearchByTagsQuery {
readonly tags: readonly {
readonly tags: ReadonlyArray<{
readonly key: string;
readonly value: string;
}[];
}>;
}
export declare type SearchTxQuery =
| SearchByIdQuery
@ -90,7 +90,7 @@ export interface Block {
readonly id: string;
readonly header: BlockHeader;
/** Array of raw transactions */
readonly txs: ReadonlyArray<Uint8Array>;
readonly txs: readonly Uint8Array[];
}
/** Use for testing only */
export interface PrivateCosmWasmClient {

View File

@ -11,7 +11,7 @@ export interface MsgSend extends Msg {
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
readonly amount: readonly Coin[];
};
}
export declare function isMsgSend(msg: Msg): msg is MsgSend;

View File

@ -3,7 +3,7 @@ import { CosmosSdkTx, StdTx } from "./types";
export interface CosmosSdkAccount {
/** Bech32 account address */
readonly address: string;
readonly coins: ReadonlyArray<Coin>;
readonly coins: readonly Coin[];
/** Bech32 encoded pubkey */
readonly public_key: string;
readonly account_number: number;
@ -69,7 +69,7 @@ interface Block {
readonly header: BlockHeader;
readonly data: {
/** Array of base64 encoded transactions */
readonly txs: ReadonlyArray<string> | null;
readonly txs: readonly string[] | null;
};
}
export interface BlockResponse {

View File

@ -17,7 +17,7 @@ export interface CosmosSdkTx {
readonly value: StdTx;
}
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly amount: readonly Coin[];
readonly gas: string;
}
export interface StdSignature {

View File

@ -17,7 +17,7 @@ import { Producer, Stream, Subscription } from "xstream";
* differently than xstream's concat as discussed in https://github.com/staltz/xstream/issues/170.
*
*/
export function concat<T>(...streams: Stream<T>[]): Stream<T> {
export function concat<T>(...streams: Array<Stream<T>>): Stream<T> {
const subscriptions = new Array<Subscription>();
const queues = new Array<T[]>(); // one queue per stream
const completedStreams = new Set<number>();

View File

@ -16,4 +16,4 @@ import { Stream } from "xstream";
* differently than xstream's concat as discussed in https://github.com/staltz/xstream/issues/170.
*
*/
export declare function concat<T>(...streams: Stream<T>[]): Stream<T>;
export declare function concat<T>(...streams: Array<Stream<T>>): Stream<T>;