diff --git a/biome.jsonc b/biome.jsonc index a6f9ad99..bdc0ba6f 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -17,7 +17,7 @@ // https://github.com/ChainSafe/ssz/pull/475#discussion_r1995814916 "useNumberNamespace": "off", // TODO: There are two many usages, will fix in separate PR - "noParameterAssign": "off", + "noParameterAssign": "warn", // We use to export types and object without differentiating "useExportType": "off", // We use to import types and object without differentiating diff --git a/packages/persistent-merkle-tree/src/node.ts b/packages/persistent-merkle-tree/src/node.ts index cafc61c3..2fc36cf6 100644 --- a/packages/persistent-merkle-tree/src/node.ts +++ b/packages/persistent-merkle-tree/src/node.ts @@ -257,12 +257,12 @@ export class LeafNode extends Node { } } - setUintBigint(uintBytes: number, offsetBytes: number, valueBN: bigint): void { + setUintBigint(uintBytes: number, offsetBytes: number, _valueBN: bigint): void { const hIndex = Math.floor(offsetBytes / 4); // number has to be masked from an h value if (uintBytes < 4) { - const value = Number(valueBN); + const value = Number(_valueBN); const bitIndex = (offsetBytes % 4) * 8; let h = getNodeH(this, hIndex); if (uintBytes === 1) { @@ -277,11 +277,12 @@ export class LeafNode extends Node { // number equals the h value else if (uintBytes === 4) { - setNodeH(this, hIndex, Number(valueBN)); + setNodeH(this, hIndex, Number(_valueBN)); } // number spans multiple h values else { + let valueBN = _valueBN; const hEnd = hIndex + Math.ceil(uintBytes / 4); for (let i = hIndex; i < hEnd; i++) { setNodeH(this, i, Number(valueBN & BigInt(0xffffffff))); @@ -290,8 +291,9 @@ export class LeafNode extends Node { } } - bitwiseOrUint(uintBytes: number, offsetBytes: number, value: number): void { + bitwiseOrUint(uintBytes: number, offsetBytes: number, _value: number): void { const hIndex = Math.floor(offsetBytes / 4); + let value = _value; // number has to be masked from an h value if (uintBytes < 4) { diff --git a/packages/persistent-merkle-tree/src/proof/single.ts b/packages/persistent-merkle-tree/src/proof/single.ts index ed956f48..84182ee8 100644 --- a/packages/persistent-merkle-tree/src/proof/single.ts +++ b/packages/persistent-merkle-tree/src/proof/single.ts @@ -20,9 +20,11 @@ export function createSingleProof(rootNode: Node, index: Gindex): [Uint8Array, U return [node.root, witnesses.reverse()]; } -export function createNodeFromSingleProof(gindex: Gindex, leaf: Uint8Array, witnesses: Uint8Array[]): Node { +export function createNodeFromSingleProof(_gindex: Gindex, leaf: Uint8Array, witnesses: Uint8Array[]): Node { let node: Node = LeafNode.fromRoot(leaf); const w = witnesses.slice().reverse(); + let gindex: Gindex = _gindex; + while (gindex > 1) { const sibling = LeafNode.fromRoot(w.pop() as Uint8Array); if (gindex % BigInt(2) === BigInt(0)) { diff --git a/packages/persistent-merkle-tree/src/subtree.ts b/packages/persistent-merkle-tree/src/subtree.ts index a40ed84c..2667a663 100644 --- a/packages/persistent-merkle-tree/src/subtree.ts +++ b/packages/persistent-merkle-tree/src/subtree.ts @@ -2,8 +2,10 @@ import {HashComputationLevel, getHashComputations, levelAtIndex} from "./hashCom import {BranchNode, Node} from "./node.ts"; import {zeroNode} from "./zeroNode.ts"; -export function subtreeFillToDepth(bottom: Node, depth: number): Node { +export function subtreeFillToDepth(bottom: Node, _depth: number): Node { let node = bottom; + let depth = _depth; + while (depth > 0) { node = new BranchNode(node, node); depth--; diff --git a/packages/ssz/src/type/arrayComposite.ts b/packages/ssz/src/type/arrayComposite.ts index 7494e279..97cde449 100644 --- a/packages/ssz/src/type/arrayComposite.ts +++ b/packages/ssz/src/type/arrayComposite.ts @@ -141,9 +141,10 @@ export function tree_serializeToBytesArrayComposite>> extends C return variableIndex; } - value_deserializeFromBytes(data: ByteViews, start: number, end: number): ValueOfFields { + value_deserializeFromBytes(data: ByteViews, _start: number, end: number): ValueOfFields { + let start = _start; const {optionalFields, fieldRanges} = this.getFieldRanges(data, start, end); const value = {} as {[K in keyof Fields]: unknown}; const optionalFieldsLen = optionalFields.uint8Array.length; @@ -349,7 +350,8 @@ export class ProfileType>> extends C return variableIndex; } - tree_deserializeFromBytes(data: ByteViews, start: number, end: number): Node { + tree_deserializeFromBytes(data: ByteViews, _start: number, end: number): Node { + let start = _start; const {optionalFields, fieldRanges} = this.getFieldRanges(data, start, end); const nodes = new Array(this.activeFields.bitLen).fill(zeroNode(0)); const optionalFieldsLen = optionalFields.uint8Array.length; diff --git a/packages/ssz/src/type/uint.ts b/packages/ssz/src/type/uint.ts index a3d5cfc4..d614cbfa 100644 --- a/packages/ssz/src/type/uint.ts +++ b/packages/ssz/src/type/uint.ts @@ -278,7 +278,8 @@ export class UintBigintType extends BasicType { // Serialization + deserialization - value_serializeToBytes({dataView}: ByteViews, offset: number, value: bigint): number { + value_serializeToBytes({dataView}: ByteViews, offset: number, _value: bigint): number { + let value = _value; switch (this.byteLength) { case 1: dataView.setInt8(offset, Number(value)); diff --git a/packages/ssz/src/util/byteArray.ts b/packages/ssz/src/util/byteArray.ts index 44dc85b0..69a214fa 100644 --- a/packages/ssz/src/util/byteArray.ts +++ b/packages/ssz/src/util/byteArray.ts @@ -14,7 +14,8 @@ export function toHexString(bytes: Uint8Array | ByteVector): string { return hex; } -export function fromHexString(hex: string): Uint8Array { +export function fromHexString(_hex: string): Uint8Array { + let hex = _hex; if (typeof hex !== "string") { throw new Error(`hex argument type ${typeof hex} must be of type string`); } diff --git a/packages/ssz/src/util/proof/treePostProcessFromProofNode.ts b/packages/ssz/src/util/proof/treePostProcessFromProofNode.ts index f479e989..5f428a1c 100644 --- a/packages/ssz/src/util/proof/treePostProcessFromProofNode.ts +++ b/packages/ssz/src/util/proof/treePostProcessFromProofNode.ts @@ -35,8 +35,9 @@ function isCompositeType(type: Type): type is CompositeType { * * @param bitstring Bitstring without the leading "1", since it's only used to compute horizontal indexes. */ -export function treePostProcessFromProofNode(node: Node, type: CompositeType, bitstring = "", currentDepth = 0): Node { +export function treePostProcessFromProofNode(_node: Node, type: CompositeType, bitstring = "", currentDepth = 0): Node { // Must run tree_fromProofNode on the first received node (i.e. Validator object) + let node: Node = _node; if (currentDepth === 0) { const nodePost = type.tree_fromProofNode(node); if (nodePost.done) return nodePost.node; diff --git a/packages/ssz/src/view/arrayBasic.ts b/packages/ssz/src/view/arrayBasic.ts index 1e32977a..477e031e 100644 --- a/packages/ssz/src/view/arrayBasic.ts +++ b/packages/ssz/src/view/arrayBasic.ts @@ -91,7 +91,8 @@ export class ArrayBasicTreeView> extends * Get all values of this array as Basic element type values, from index zero to `this.length - 1` * @param values optional output parameter, if is provided it must be an array of the same length as this array */ - getAll(values?: ValueOf[]): ValueOf[] { + getAll(_values?: ValueOf[]): ValueOf[] { + let values = _values; if (values && values.length !== this.length) { throw Error(`Expected ${this.length} values, got ${values.length}`); } diff --git a/packages/ssz/src/view/arrayComposite.ts b/packages/ssz/src/view/arrayComposite.ts index 6a93583e..97624cb3 100644 --- a/packages/ssz/src/view/arrayComposite.ts +++ b/packages/ssz/src/view/arrayComposite.ts @@ -78,7 +78,8 @@ export class ArrayCompositeTreeView< * propagated upwards. To get linked element Views use `this.get()` * @param views optional output parameter, if is provided it must be an array of the same length as this array */ - getAllReadonly(views?: CompositeView[]): CompositeView[] { + getAllReadonly(_views?: CompositeView[]): CompositeView[] { + let views = _views; if (views && views.length !== this.length) { throw Error(`Expected ${this.length} views, got ${views.length}`); } @@ -99,7 +100,8 @@ export class ArrayCompositeTreeView< * To get linked element Views use `this.get()` * @param values optional output parameter, if is provided it must be an array of the same length as this array */ - getAllReadonlyValues(values?: ValueOf[]): ValueOf[] { + getAllReadonlyValues(_values?: ValueOf[]): ValueOf[] { + let values = _values; if (values && values.length !== this.length) { throw Error(`Expected ${this.length} values, got ${values.length}`); } diff --git a/packages/ssz/src/viewDU/arrayBasic.ts b/packages/ssz/src/viewDU/arrayBasic.ts index 6bae7912..e15cd9d5 100644 --- a/packages/ssz/src/viewDU/arrayBasic.ts +++ b/packages/ssz/src/viewDU/arrayBasic.ts @@ -111,7 +111,8 @@ export class ArrayBasicTreeViewDU> extend * Get all values of this array as Basic element type values, from index zero to `this.length - 1` * @param values optional output parameter, if is provided it must be an array of the same length as this array */ - getAll(values?: ValueOf[]): ValueOf[] { + getAll(_values?: ValueOf[]): ValueOf[] { + let values = _values; if (values && values.length !== this._length) { throw Error(`Expected ${this._length} values, got ${values.length}`); } diff --git a/packages/ssz/src/viewDU/arrayComposite.ts b/packages/ssz/src/viewDU/arrayComposite.ts index d38d160a..90b67a3e 100644 --- a/packages/ssz/src/viewDU/arrayComposite.ts +++ b/packages/ssz/src/viewDU/arrayComposite.ts @@ -149,7 +149,8 @@ export class ArrayCompositeTreeViewDU< * No need to commit() before calling this function. * @param views optional output parameter, if is provided it must be an array of the same length as this array */ - getAllReadonly(views?: CompositeViewDU[]): CompositeViewDU[] { + getAllReadonly(_views?: CompositeViewDU[]): CompositeViewDU[] { + let views = _views; if (views && views.length !== this._length) { throw Error(`Expected ${this._length} views, got ${views.length}`); } @@ -179,7 +180,8 @@ export class ArrayCompositeTreeViewDU< * WARNING: Returns all commited changes, if there are any pending changes commit them beforehand * @param values optional output parameter, if is provided it must be an array of the same length as this array */ - getAllReadonlyValues(values?: ValueOf[]): ValueOf[] { + getAllReadonlyValues(_values?: ValueOf[]): ValueOf[] { + let values = _values; if (values && values.length !== this._length) { throw Error(`Expected ${this._length} values, got ${values.length}`); } @@ -206,7 +208,8 @@ export class ArrayCompositeTreeViewDU< * Get by range of indexes. Returns an array of views of the Composite element type. * This is similar to getAllReadonly() where we dont have to commit() before calling this function. */ - getReadonlyByRange(startIndex: number, count: number): CompositeViewDU[] { + getReadonlyByRange(startIndex: number, _count: number): CompositeViewDU[] { + let count = _count; if (startIndex < 0) { throw Error(`Error getting by range, startIndex < 0: ${startIndex}`); } diff --git a/packages/ssz/src/viewDU/listComposite.ts b/packages/ssz/src/viewDU/listComposite.ts index 95d51f8f..ca214b7f 100644 --- a/packages/ssz/src/viewDU/listComposite.ts +++ b/packages/ssz/src/viewDU/listComposite.ts @@ -79,7 +79,8 @@ export class ListCompositeTreeViewDU< * Note: If index === n, returns an empty list of length 0 * */ - sliceFrom(index: number): this { + sliceFrom(_index: number): this { + let index = _index; // Commit before getting rootNode to ensure all pending data is in the rootNode this.commit(); // populate to `this.nodes` to ensure all nodes are loaded diff --git a/packages/ssz/test/lodestarTypes/phase0/validator.ts b/packages/ssz/test/lodestarTypes/phase0/validator.ts index 346d6857..1cfc5f43 100644 --- a/packages/ssz/test/lodestarTypes/phase0/validator.ts +++ b/packages/ssz/test/lodestarTypes/phase0/validator.ts @@ -39,9 +39,10 @@ export class ValidatorNodeStructType extends ContainerNodeStructType ): number { + let offset = _offset; output.set(validator.pubkey, offset); offset += PUBKEY_SIZE; output.set(validator.withdrawalCredentials, offset); @@ -115,7 +116,8 @@ export function validatorToChunkBytes( writeEpochInf(dataView, offset, withdrawableEpoch); } -function writeEpochInf(dataView: DataView, offset: number, value: number): number { +function writeEpochInf(dataView: DataView, _offset: number, value: number): number { + let offset = _offset; if (value === Infinity) { dataView.setUint32(offset, 0xffffffff, true); offset += UINT32_SIZE; diff --git a/packages/ssz/test/unit/byType/runTypeProofTest.ts b/packages/ssz/test/unit/byType/runTypeProofTest.ts index 501abe96..de67a8a6 100644 --- a/packages/ssz/test/unit/byType/runTypeProofTest.ts +++ b/packages/ssz/test/unit/byType/runTypeProofTest.ts @@ -102,7 +102,8 @@ function getJsonPathsFromValue(value: unknown, parentPath: JsonPath = [], jsonPa /** * Returns the end type of a JSON path */ -function getJsonPathType(type: CompositeTypeAny, jsonPath: JsonPath): Type { +function getJsonPathType(_type: CompositeTypeAny, jsonPath: JsonPath): Type { + let type = _type; for (const jsonProp of jsonPath) { type = type.getPropertyType(jsonProp) as CompositeTypeAny; } @@ -114,7 +115,9 @@ function getJsonPathType(type: CompositeTypeAny, jsonPath: JsonPath): Type, view: unknown, jsonPath: JsonPath): unknown { +function getJsonPathView(_type: Type, _view: unknown, jsonPath: JsonPath): unknown { + let type = _type; + let view = _view; for (const jsonProp of jsonPath) { if (type instanceof OptionalType) { type = type.elementType; @@ -146,7 +149,9 @@ function getJsonPathView(type: Type, view: unknown, jsonPath: JsonPath) * Requires the type to coerce jsonProp to a fieldName. * JSON paths may be in JSON notation or fieldName notation */ -function getJsonPathValue(type: Type, json: unknown, jsonPath: JsonPath): unknown { +function getJsonPathValue(_type: Type, _json: unknown, jsonPath: JsonPath): unknown { + let type = _type; + let json = _json; for (const jsonProp of jsonPath) { if (type instanceof OptionalType) { type = type.elementType;