From 3b46bd42c6d4bbe32b11c7b7522ca844d4338b8c Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 14 Aug 2023 20:00:45 -0400 Subject: [PATCH] Fix VSCode reported lint issues (#4153, #4156, #4158, #4159). --- src.ts/_admin/test-browser.ts | 2 +- src.ts/_tests/test-contract.ts | 2 +- src.ts/_tests/test-wallet-mnemonic.ts | 2 +- src.ts/abi/coders/abstract-coder.ts | 4 ++-- src.ts/abi/coders/array.ts | 4 ++-- src.ts/abi/fragments.ts | 8 ++++---- src.ts/abi/interface.ts | 6 +++--- src.ts/contract/contract.ts | 2 +- src.ts/providers/abstract-provider.ts | 3 ++- src.ts/providers/provider-fallback.ts | 2 +- src.ts/utils/rlp-decode.ts | 2 +- src.ts/utils/rlp-encode.ts | 2 +- src.ts/utils/utf8.ts | 6 +++--- src.ts/wordlists/lang-ja.ts | 4 ++-- src.ts/wordlists/lang-zh.ts | 2 +- 15 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src.ts/_admin/test-browser.ts b/src.ts/_admin/test-browser.ts index 9828997c1b..3f79c64b3d 100644 --- a/src.ts/_admin/test-browser.ts +++ b/src.ts/_admin/test-browser.ts @@ -201,7 +201,7 @@ const TestData = (function() { return [ String(data.length), zlib.deflateRawSync(data).toString("base64") ].join(","); } - let data = [ ]; + let data: Array = [ ]; data.push(`import { ethers } from "/index.js";`); data.push(`import { inflate } from "/static/tiny-inflate.js";`); data.push(`const fs = new Map();`); diff --git a/src.ts/_tests/test-contract.ts b/src.ts/_tests/test-contract.ts index 0e039b47f5..2675a046a6 100644 --- a/src.ts/_tests/test-contract.ts +++ b/src.ts/_tests/test-contract.ts @@ -249,7 +249,7 @@ describe("Test Typed Contract Interaction", function() { } ]; - const abi = [ ]; + const abi: Array = [ ]; for (let i = 1; i <= 32; i++) { abi.push(`function testTyped(uint${ i * 8 }) public pure returns (string memory)`); abi.push(`function testTyped(int${ i * 8 }) public pure returns (string memory)`); diff --git a/src.ts/_tests/test-wallet-mnemonic.ts b/src.ts/_tests/test-wallet-mnemonic.ts index 8d8e234f11..ae596c9817 100644 --- a/src.ts/_tests/test-wallet-mnemonic.ts +++ b/src.ts/_tests/test-wallet-mnemonic.ts @@ -18,7 +18,7 @@ function fromHex(hex: string): string { } function repeat(text: string, length: number): Array { - const result = [ ]; + const result: Array = [ ]; while (result.length < length) { result.push(text); } return result; } diff --git a/src.ts/abi/coders/abstract-coder.ts b/src.ts/abi/coders/abstract-coder.ts index 8a4521a69d..6e46e5ca1c 100644 --- a/src.ts/abi/coders/abstract-coder.ts +++ b/src.ts/abi/coders/abstract-coder.ts @@ -182,7 +182,7 @@ export class Result extends Array { } if (end > this.length) { end = this.length; } - const result = [ ], names = [ ]; + const result: Array = [ ], names: Array = [ ]; for (let i = start; i < end; i++) { result.push(this[i]); names.push(this.#names[i]); @@ -195,7 +195,7 @@ export class Result extends Array { * @_ignore */ filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result { - const result = [ ], names = [ ]; + const result: Array = [ ], names: Array = [ ]; for (let i = 0; i < this.length; i++) { const item = this[i]; if (item instanceof Error) { diff --git a/src.ts/abi/coders/array.ts b/src.ts/abi/coders/array.ts index 3270713df8..9323ed9759 100644 --- a/src.ts/abi/coders/array.ts +++ b/src.ts/abi/coders/array.ts @@ -171,7 +171,7 @@ export class ArrayCoder extends Coder { assertArgumentCount(value.length, count, "coder array" + (this.localName? (" "+ this.localName): "")); - let coders = []; + let coders: Array = [ ]; for (let i = 0; i < value.length; i++) { coders.push(this.coder); } return pack(writer, coders, value); @@ -190,7 +190,7 @@ export class ArrayCoder extends Coder { assert(count * WordSize <= reader.dataLength, "insufficient data length", "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * WordSize, length: reader.dataLength }); } - let coders = []; + let coders: Array = []; for (let i = 0; i < count; i++) { coders.push(new AnonymousCoder(this.coder)); } return unpack(reader, coders); diff --git a/src.ts/abi/fragments.ts b/src.ts/abi/fragments.ts index c58f4fabcd..b8a87b5c4c 100644 --- a/src.ts/abi/fragments.ts +++ b/src.ts/abi/fragments.ts @@ -843,7 +843,7 @@ export class ParamType { comps = null; } - let indexed = null; + let indexed: null | boolean = null; const keywords = consumeKeywords(obj, KwModifiers); if (keywords.has("indexed")) { if (!allowIndexed) { throw new Error(""); } @@ -1079,7 +1079,7 @@ export class ErrorFragment extends NamedFragment { }); } - const result = [ ]; + const result: Array = [ ]; if (format !== "sighash") { result.push("error"); } result.push(this.name + joinParams(format, this.inputs)); return result.join(" "); @@ -1154,7 +1154,7 @@ export class EventFragment extends NamedFragment { }); } - const result = [ ]; + const result: Array = [ ]; if (format !== "sighash") { result.push("event"); } result.push(this.name + joinParams(format, this.inputs)); if (format !== "sighash" && this.anonymous) { result.push("anonymous"); } @@ -1465,7 +1465,7 @@ export class FunctionFragment extends NamedFragment { }); } - const result = []; + const result: Array = []; if (format !== "sighash") { result.push("function"); } diff --git a/src.ts/abi/interface.ts b/src.ts/abi/interface.ts index 110f89ebf9..e453f6ad51 100644 --- a/src.ts/abi/interface.ts +++ b/src.ts/abi/interface.ts @@ -595,7 +595,7 @@ export class Interface { // It is a bare name, look up the function (will return null if ambiguous) if (key.indexOf("(") === -1) { - const matching = [ ]; + const matching: Array = [ ]; for (const [ name, fragment ] of this.#events) { if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } } @@ -716,7 +716,7 @@ export class Interface { // It is a bare name, look up the function (will return null if ambiguous) if (key.indexOf("(") === -1) { - const matching = [ ]; + const matching: Array = [ ]; for (const [ name, fragment ] of this.#errors) { if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } } @@ -1154,7 +1154,7 @@ export class Interface { const keys: Array = [ ]; let nonIndexedIndex = 0, indexedIndex = 0; fragment.inputs.forEach((param, index) => { - let value = null; + let value: null | Indexed = null; if (param.indexed) { if (resultIndexed == null) { value = new Indexed(null); diff --git a/src.ts/contract/contract.ts b/src.ts/contract/contract.ts index 0c6e9d6448..5895367105 100644 --- a/src.ts/contract/contract.ts +++ b/src.ts/contract/contract.ts @@ -679,7 +679,7 @@ export class BaseContract implements Addressable, EventEmitterable): undefined | } let bestWeight = 0; - let bestResult = undefined; + let bestResult: undefined | number = undefined; for (const { weight, result } of tally.values()) { // Use this result, if this result meets quorum and has either: diff --git a/src.ts/utils/rlp-decode.ts b/src.ts/utils/rlp-decode.ts index acb3a21adf..330ba5cf9e 100644 --- a/src.ts/utils/rlp-decode.ts +++ b/src.ts/utils/rlp-decode.ts @@ -27,7 +27,7 @@ type Decoded = { }; function _decodeChildren(data: Uint8Array, offset: number, childOffset: number, length: number): Decoded { - const result = []; + const result: Array = []; while (childOffset < offset + 1 + length) { const decoded = _decode(data, childOffset); diff --git a/src.ts/utils/rlp-encode.ts b/src.ts/utils/rlp-encode.ts index 9800e4b2f6..a2cd0bcadd 100644 --- a/src.ts/utils/rlp-encode.ts +++ b/src.ts/utils/rlp-encode.ts @@ -6,7 +6,7 @@ import type { RlpStructuredData } from "./rlp.js"; function arrayifyInteger(value: number): Array { - const result = []; + const result: Array = []; while (value) { result.unshift(value & 0xff); value >>= 8; diff --git a/src.ts/utils/utf8.ts b/src.ts/utils/utf8.ts index 19cba00e77..0e893cd98c 100644 --- a/src.ts/utils/utf8.ts +++ b/src.ts/utils/utf8.ts @@ -162,8 +162,8 @@ function getUtf8CodePoints(_bytes: BytesLike, onError?: Utf8ErrorFunc): Array = []; for (let i = 0; i < str.length; i++) { const c = str.charCodeAt(i); diff --git a/src.ts/wordlists/lang-ja.ts b/src.ts/wordlists/lang-ja.ts index 7b1f2aaf32..e4b6cdce7f 100644 --- a/src.ts/wordlists/lang-ja.ts +++ b/src.ts/wordlists/lang-ja.ts @@ -49,7 +49,7 @@ function toString(data: Array): string { function loadWords(): Array { if (_wordlist !== null) { return _wordlist; } - const wordlist = []; + const wordlist: Array = []; // Transforms for normalizing (sort is a not quite UTF-8) const transform: { [key: string]: string | boolean } = {}; @@ -91,7 +91,7 @@ function loadWords(): Array { for (let length = 3; length <= 9; length++) { const d = data[length - 3]; for (let offset = 0; offset < d.length; offset += length) { - const word = []; + const word: Array = []; for (let i = 0; i < length; i++) { const k = mapping.indexOf(d[offset + i]); word.push(227); diff --git a/src.ts/wordlists/lang-zh.ts b/src.ts/wordlists/lang-zh.ts index 048115bce8..cd96f6937b 100644 --- a/src.ts/wordlists/lang-zh.ts +++ b/src.ts/wordlists/lang-zh.ts @@ -24,7 +24,7 @@ const style = "~!@#$%^&*_-=[]{}|;:,.()<>?" function loadWords(locale: string): Array { if (_wordlist[locale] != null) { return _wordlist[locale] as Array; } - const wordlist = []; + const wordlist: Array = []; let deltaOffset = 0; for (let i = 0; i < 2048; i++) {