Fix VSCode reported lint issues (#4153, #4156, #4158, #4159).

This commit is contained in:
Richard Moore 2023-08-14 20:00:45 -04:00
parent 609e2f53eb
commit 4eb84da865
15 changed files with 26 additions and 25 deletions

View File

@ -201,7 +201,7 @@ const TestData = (function() {
return [ String(data.length), zlib.deflateRawSync(data).toString("base64") ].join(","); return [ String(data.length), zlib.deflateRawSync(data).toString("base64") ].join(",");
} }
let data = [ ]; let data: Array<string> = [ ];
data.push(`import { ethers } from "/index.js";`); data.push(`import { ethers } from "/index.js";`);
data.push(`import { inflate } from "/static/tiny-inflate.js";`); data.push(`import { inflate } from "/static/tiny-inflate.js";`);
data.push(`const fs = new Map();`); data.push(`const fs = new Map();`);

View File

@ -249,7 +249,7 @@ describe("Test Typed Contract Interaction", function() {
} }
]; ];
const abi = [ ]; const abi: Array<string> = [ ];
for (let i = 1; i <= 32; i++) { for (let i = 1; i <= 32; i++) {
abi.push(`function testTyped(uint${ i * 8 }) public pure returns (string memory)`); abi.push(`function testTyped(uint${ i * 8 }) public pure returns (string memory)`);
abi.push(`function testTyped(int${ i * 8 }) public pure returns (string memory)`); abi.push(`function testTyped(int${ i * 8 }) public pure returns (string memory)`);

View File

@ -18,7 +18,7 @@ function fromHex(hex: string): string {
} }
function repeat(text: string, length: number): Array<string> { function repeat(text: string, length: number): Array<string> {
const result = [ ]; const result: Array<string> = [ ];
while (result.length < length) { result.push(text); } while (result.length < length) { result.push(text); }
return result; return result;
} }

View File

@ -182,7 +182,7 @@ export class Result extends Array<any> {
} }
if (end > this.length) { end = this.length; } if (end > this.length) { end = this.length; }
const result = [ ], names = [ ]; const result: Array<any> = [ ], names: Array<null | string> = [ ];
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
result.push(this[i]); result.push(this[i]);
names.push(this.#names[i]); names.push(this.#names[i]);
@ -195,7 +195,7 @@ export class Result extends Array<any> {
* @_ignore * @_ignore
*/ */
filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result { filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result {
const result = [ ], names = [ ]; const result: Array<any> = [ ], names: Array<null | string> = [ ];
for (let i = 0; i < this.length; i++) { for (let i = 0; i < this.length; i++) {
const item = this[i]; const item = this[i];
if (item instanceof Error) { if (item instanceof Error) {

View File

@ -171,7 +171,7 @@ export class ArrayCoder extends Coder {
assertArgumentCount(value.length, count, "coder array" + (this.localName? (" "+ this.localName): "")); assertArgumentCount(value.length, count, "coder array" + (this.localName? (" "+ this.localName): ""));
let coders = []; let coders: Array<Coder> = [ ];
for (let i = 0; i < value.length; i++) { coders.push(this.coder); } for (let i = 0; i < value.length; i++) { coders.push(this.coder); }
return pack(writer, coders, value); return pack(writer, coders, value);
@ -190,7 +190,7 @@ export class ArrayCoder extends Coder {
assert(count * WordSize <= reader.dataLength, "insufficient data length", assert(count * WordSize <= reader.dataLength, "insufficient data length",
"BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * WordSize, length: reader.dataLength }); "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * WordSize, length: reader.dataLength });
} }
let coders = []; let coders: Array<Coder> = [];
for (let i = 0; i < count; i++) { coders.push(new AnonymousCoder(this.coder)); } for (let i = 0; i < count; i++) { coders.push(new AnonymousCoder(this.coder)); }
return unpack(reader, coders); return unpack(reader, coders);

View File

@ -843,7 +843,7 @@ export class ParamType {
comps = null; comps = null;
} }
let indexed = null; let indexed: null | boolean = null;
const keywords = consumeKeywords(obj, KwModifiers); const keywords = consumeKeywords(obj, KwModifiers);
if (keywords.has("indexed")) { if (keywords.has("indexed")) {
if (!allowIndexed) { throw new Error(""); } if (!allowIndexed) { throw new Error(""); }
@ -1079,7 +1079,7 @@ export class ErrorFragment extends NamedFragment {
}); });
} }
const result = [ ]; const result: Array<string> = [ ];
if (format !== "sighash") { result.push("error"); } if (format !== "sighash") { result.push("error"); }
result.push(this.name + joinParams(format, this.inputs)); result.push(this.name + joinParams(format, this.inputs));
return result.join(" "); return result.join(" ");
@ -1154,7 +1154,7 @@ export class EventFragment extends NamedFragment {
}); });
} }
const result = [ ]; const result: Array<string> = [ ];
if (format !== "sighash") { result.push("event"); } if (format !== "sighash") { result.push("event"); }
result.push(this.name + joinParams(format, this.inputs)); result.push(this.name + joinParams(format, this.inputs));
if (format !== "sighash" && this.anonymous) { result.push("anonymous"); } if (format !== "sighash" && this.anonymous) { result.push("anonymous"); }
@ -1465,7 +1465,7 @@ export class FunctionFragment extends NamedFragment {
}); });
} }
const result = []; const result: Array<string> = [];
if (format !== "sighash") { result.push("function"); } if (format !== "sighash") { result.push("function"); }

View File

@ -595,7 +595,7 @@ export class Interface {
// It is a bare name, look up the function (will return null if ambiguous) // It is a bare name, look up the function (will return null if ambiguous)
if (key.indexOf("(") === -1) { if (key.indexOf("(") === -1) {
const matching = [ ]; const matching: Array<EventFragment> = [ ];
for (const [ name, fragment ] of this.#events) { for (const [ name, fragment ] of this.#events) {
if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } 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) // It is a bare name, look up the function (will return null if ambiguous)
if (key.indexOf("(") === -1) { if (key.indexOf("(") === -1) {
const matching = [ ]; const matching: Array<ErrorFragment> = [ ];
for (const [ name, fragment ] of this.#errors) { for (const [ name, fragment ] of this.#errors) {
if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); }
} }
@ -1154,7 +1154,7 @@ export class Interface {
const keys: Array<null | string> = [ ]; const keys: Array<null | string> = [ ];
let nonIndexedIndex = 0, indexedIndex = 0; let nonIndexedIndex = 0, indexedIndex = 0;
fragment.inputs.forEach((param, index) => { fragment.inputs.forEach((param, index) => {
let value = null; let value: null | Indexed = null;
if (param.indexed) { if (param.indexed) {
if (resultIndexed == null) { if (resultIndexed == null) {
value = new Indexed(null); value = new Indexed(null);

View File

@ -679,7 +679,7 @@ export class BaseContract implements Addressable, EventEmitterable<ContractEvent
Object.defineProperty(this, internal, { value: { } }); Object.defineProperty(this, internal, { value: { } });
let addrPromise; let addrPromise;
let addr = null; let addr: null | string = null;
let deployTx: null | ContractTransactionResponse = null; let deployTx: null | ContractTransactionResponse = null;
if (_deployTx) { if (_deployTx) {

View File

@ -907,7 +907,8 @@ export class AbstractProvider implements Provider {
})()) })())
}); });
let maxFeePerGas = null, maxPriorityFeePerGas = null; let maxFeePerGas: null | bigint = null;
let maxPriorityFeePerGas: null | bigint = null;
// These are the recommended EIP-1559 heuristics for fee data // These are the recommended EIP-1559 heuristics for fee data
const block = this._wrapBlock(_block, network); const block = this._wrapBlock(_block, network);

View File

@ -332,7 +332,7 @@ function getFuzzyMode(quorum: number, results: Array<TallyResult>): undefined |
} }
let bestWeight = 0; let bestWeight = 0;
let bestResult = undefined; let bestResult: undefined | number = undefined;
for (const { weight, result } of tally.values()) { for (const { weight, result } of tally.values()) {
// Use this result, if this result meets quorum and has either: // Use this result, if this result meets quorum and has either:

View File

@ -27,7 +27,7 @@ type Decoded = {
}; };
function _decodeChildren(data: Uint8Array, offset: number, childOffset: number, length: number): Decoded { function _decodeChildren(data: Uint8Array, offset: number, childOffset: number, length: number): Decoded {
const result = []; const result: Array<any> = [];
while (childOffset < offset + 1 + length) { while (childOffset < offset + 1 + length) {
const decoded = _decode(data, childOffset); const decoded = _decode(data, childOffset);

View File

@ -6,7 +6,7 @@ import type { RlpStructuredData } from "./rlp.js";
function arrayifyInteger(value: number): Array<number> { function arrayifyInteger(value: number): Array<number> {
const result = []; const result: Array<number> = [];
while (value) { while (value) {
result.unshift(value & 0xff); result.unshift(value & 0xff);
value >>= 8; value >>= 8;

View File

@ -162,8 +162,8 @@ function getUtf8CodePoints(_bytes: BytesLike, onError?: Utf8ErrorFunc): Array<nu
} }
// Multibyte; how many bytes left for this character? // Multibyte; how many bytes left for this character?
let extraLength = null; let extraLength: null | number = null;
let overlongMask = null; let overlongMask: null | number = null;
// 110x xxxx 10xx xxxx // 110x xxxx 10xx xxxx
if ((c & 0xe0) === 0xc0) { if ((c & 0xe0) === 0xc0) {
@ -253,7 +253,7 @@ export function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8
str = str.normalize(form); str = str.normalize(form);
} }
let result = []; let result: Array<number> = [];
for (let i = 0; i < str.length; i++) { for (let i = 0; i < str.length; i++) {
const c = str.charCodeAt(i); const c = str.charCodeAt(i);

View File

@ -49,7 +49,7 @@ function toString(data: Array<number>): string {
function loadWords(): Array<string> { function loadWords(): Array<string> {
if (_wordlist !== null) { return _wordlist; } if (_wordlist !== null) { return _wordlist; }
const wordlist = []; const wordlist: Array<string> = [];
// Transforms for normalizing (sort is a not quite UTF-8) // Transforms for normalizing (sort is a not quite UTF-8)
const transform: { [key: string]: string | boolean } = {}; const transform: { [key: string]: string | boolean } = {};
@ -91,7 +91,7 @@ function loadWords(): Array<string> {
for (let length = 3; length <= 9; length++) { for (let length = 3; length <= 9; length++) {
const d = data[length - 3]; const d = data[length - 3];
for (let offset = 0; offset < d.length; offset += length) { for (let offset = 0; offset < d.length; offset += length) {
const word = []; const word: Array<number> = [];
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
const k = mapping.indexOf(d[offset + i]); const k = mapping.indexOf(d[offset + i]);
word.push(227); word.push(227);

View File

@ -24,7 +24,7 @@ const style = "~!@#$%^&*_-=[]{}|;:,.()<>?"
function loadWords(locale: string): Array<string> { function loadWords(locale: string): Array<string> {
if (_wordlist[locale] != null) { return _wordlist[locale] as Array<string>; } if (_wordlist[locale] != null) { return _wordlist[locale] as Array<string>; }
const wordlist = []; const wordlist: Array<string> = [];
let deltaOffset = 0; let deltaOffset = 0;
for (let i = 0; i < 2048; i++) { for (let i = 0; i < 2048; i++) {