From a362c548bf0bc1b1503d7d6fc3b6013e6ed12277 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Sun, 7 Apr 2024 12:56:58 -0400 Subject: [PATCH 1/3] fix: Switch to biome --- .eslintrc | 64 -------------------------------- biome.json | 2 +- package.json | 12 +----- src/constants/constants.ts | 52 +++++++++++++------------- src/index.test.ts | 14 +++---- src/lib/decodeData.test.ts | 11 ++++-- src/lib/decodeData.ts | 11 +++--- src/lib/decodeMappingKey.test.ts | 4 +- src/lib/decodeMappingKey.ts | 17 +++++---- src/lib/encodeKeyName.ts | 2 +- src/lib/encoder.test.ts | 2 +- src/lib/encoder.ts | 33 ++++++++-------- src/lib/getData.ts | 3 +- src/lib/schemaParser.ts | 2 +- src/lib/utils.test.ts | 2 +- test/mockProviders.ts | 8 ++-- 16 files changed, 86 insertions(+), 153 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 6d6e900b..00000000 --- a/.eslintrc +++ /dev/null @@ -1,64 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true, - "node": true, - "mocha": true - }, - "parserOptions": { - "ecmaVersion": 12, - "sourceType": "module" - }, - "parser": "@typescript-eslint/parser", - "plugins": ["prettier", "@typescript-eslint"], - "extends": [ - "airbnb-base", - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "plugin:prettier/recommended" - ], - "settings": { - "import/resolver": { - "node": { - "extensions": [".js", ".jsx", ".ts", ".tsx"], - "moduleDirectory": ["node_modules"], - "paths": ["."] - } - } - }, - "rules": { - "prettier/prettier": "error", - // TYPESCRIPT - "@typescript-eslint/no-shadow": ["error"], - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-use-before-define": ["error"], - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/ban-ts-ignore": "off", - "@typescript-eslint/ban-ts-comment": "off", - // OTHER - "class-methods-use-this": "off", - "no-shadow": "off", - "no-console": "off", - "import/extensions": ["error", "always", { "ts": "never", "js": "never" }], - "max-classes-per-file": ["error", 3], - "no-underscore-dangle": ["error", { "allowAfterThis": true }], - "import/no-extraneous-dependencies": [ - "error", - { - "devDependencies": true, - "optionalDependencies": false, - "peerDependencies": false - } - ], - "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], - "lines-between-class-members": "off", - "prefer-template": 0, // Allow simple string concatenation - "no-await-in-loop": 0, // NOTE: This should be removed? - "import/prefer-default-export": 0, - "arrow-body-style": "off", - "no-bitwise": "off" - }, - "ignorePatterns": ["node_modules/**/*", "build/**/*"] -} diff --git a/biome.json b/biome.json index d274c243..7d2d9164 100644 --- a/biome.json +++ b/biome.json @@ -30,6 +30,6 @@ "enabled": false }, "files": { - "ignore": ["node_modules", "build", "coverage", ".vscode"] + "ignore": ["node_modules", ".nyc_output", "build", "coverage", ".vscode"] } } diff --git a/package.json b/package.json index 6ac2cc9c..82fe37cb 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,7 @@ "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", "module": "build/module/src/index.js", - "files": [ - "build", - "schemas", - "docs" - ], + "files": ["build", "schemas", "docs"], "scripts": { "build": "run-p build:*", "build:main": "tsc -p tsconfig.json", @@ -24,11 +20,7 @@ "type": "git", "url": "git+https://github.com/ERC725Alliance/erc725.js" }, - "keywords": [ - "ethereum", - "erc725", - "lsp" - ], + "keywords": ["ethereum", "erc725", "lsp"], "contributors": [ { "name": "Robert McLeod", diff --git a/src/constants/constants.ts b/src/constants/constants.ts index f28a6852..90e8b397 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -154,33 +154,33 @@ export const HASH_METHODS: { }; // TODO: These values can be imported from lsp-smartcontracts lib after release -// prettier-ignore +// biome-ignore format: Keep numeric alignment export const LSP6_DEFAULT_PERMISSIONS = { - CHANGEOWNER : "0x0000000000000000000000000000000000000000000000000000000000000001", - ADDCONTROLLER : "0x0000000000000000000000000000000000000000000000000000000000000002", - EDITPERMISSIONS : "0x0000000000000000000000000000000000000000000000000000000000000004", - ADDEXTENSIONS : "0x0000000000000000000000000000000000000000000000000000000000000008", - CHANGEEXTENSIONS : "0x0000000000000000000000000000000000000000000000000000000000000010", - ADDUNIVERSALRECEIVERDELEGATE : "0x0000000000000000000000000000000000000000000000000000000000000020", - CHANGEUNIVERSALRECEIVERDELEGATE : "0x0000000000000000000000000000000000000000000000000000000000000040", - REENTRANCY : "0x0000000000000000000000000000000000000000000000000000000000000080", - SUPER_TRANSFERVALUE : "0x0000000000000000000000000000000000000000000000000000000000000100", - TRANSFERVALUE : "0x0000000000000000000000000000000000000000000000000000000000000200", - SUPER_CALL : "0x0000000000000000000000000000000000000000000000000000000000000400", - CALL : "0x0000000000000000000000000000000000000000000000000000000000000800", - SUPER_STATICCALL : "0x0000000000000000000000000000000000000000000000000000000000001000", - STATICCALL : "0x0000000000000000000000000000000000000000000000000000000000002000", - SUPER_DELEGATECALL : "0x0000000000000000000000000000000000000000000000000000000000004000", - DELEGATECALL : "0x0000000000000000000000000000000000000000000000000000000000008000", - DEPLOY : "0x0000000000000000000000000000000000000000000000000000000000010000", - SUPER_SETDATA : "0x0000000000000000000000000000000000000000000000000000000000020000", - SETDATA : "0x0000000000000000000000000000000000000000000000000000000000040000", - ENCRYPT : "0x0000000000000000000000000000000000000000000000000000000000080000", - DECRYPT : "0x0000000000000000000000000000000000000000000000000000000000100000", - SIGN : "0x0000000000000000000000000000000000000000000000000000000000200000", - EXECUTE_RELAY_CALL : "0x0000000000000000000000000000000000000000000000000000000000400000", - ERC4337_PERMISSION : "0x0000000000000000000000000000000000000000000000000000000000800000", - ALL_PERMISSIONS : "0x00000000000000000000000000000000000000000000000000000000007f3f7f" // lsp6 v0.14.0 + CHANGEOWNER : '0x0000000000000000000000000000000000000000000000000000000000000001', + ADDCONTROLLER : '0x0000000000000000000000000000000000000000000000000000000000000002', + EDITPERMISSIONS : '0x0000000000000000000000000000000000000000000000000000000000000004', + ADDEXTENSIONS : '0x0000000000000000000000000000000000000000000000000000000000000008', + CHANGEEXTENSIONS : '0x0000000000000000000000000000000000000000000000000000000000000010', + ADDUNIVERSALRECEIVERDELEGATE : '0x0000000000000000000000000000000000000000000000000000000000000020', + CHANGEUNIVERSALRECEIVERDELEGATE : '0x0000000000000000000000000000000000000000000000000000000000000040', + REENTRANCY : '0x0000000000000000000000000000000000000000000000000000000000000080', + SUPER_TRANSFERVALUE : '0x0000000000000000000000000000000000000000000000000000000000000100', + TRANSFERVALUE : '0x0000000000000000000000000000000000000000000000000000000000000200', + SUPER_CALL : '0x0000000000000000000000000000000000000000000000000000000000000400', + CALL : '0x0000000000000000000000000000000000000000000000000000000000000800', + SUPER_STATICCALL : '0x0000000000000000000000000000000000000000000000000000000000001000', + STATICCALL : '0x0000000000000000000000000000000000000000000000000000000000002000', + SUPER_DELEGATECALL : '0x0000000000000000000000000000000000000000000000000000000000004000', + DELEGATECALL : '0x0000000000000000000000000000000000000000000000000000000000008000', + DEPLOY : '0x0000000000000000000000000000000000000000000000000000000000010000', + SUPER_SETDATA : '0x0000000000000000000000000000000000000000000000000000000000020000', + SETDATA : '0x0000000000000000000000000000000000000000000000000000000000040000', + ENCRYPT : '0x0000000000000000000000000000000000000000000000000000000000080000', + DECRYPT : '0x0000000000000000000000000000000000000000000000000000000000100000', + SIGN : '0x0000000000000000000000000000000000000000000000000000000000200000', + EXECUTE_RELAY_CALL : '0x0000000000000000000000000000000000000000000000000000000000400000', + ERC4337_PERMISSION : '0x0000000000000000000000000000000000000000000000000000000000800000', + ALL_PERMISSIONS : '0x00000000000000000000000000000000000000000000000000000000007f3f7f' }; export const LSP6_ALL_PERMISSIONS = diff --git a/src/index.test.ts b/src/index.test.ts index fded7129..22913248 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -845,7 +845,7 @@ describe('Running @erc725/erc725.js tests...', () => { describe('Getting data by schema element by provider', () => { mockSchema.forEach((schemaElement) => { - it(schemaElement.name + ' with web3.currentProvider', async () => { + it(`${schemaElement.name} with web3.currentProvider`, async () => { const returnRawData = generateAllRawData([schemaElement], false); const provider = new HttpProvider({ returnData: returnRawData }, [ ERC725Y_INTERFACE_IDS.legacy, @@ -866,7 +866,7 @@ describe('Running @erc725/erc725.js tests...', () => { }); }); - it(schemaElement.name + ' with ethereumProvider EIP 1193', async () => { + it(`${schemaElement.name} with ethereumProvider EIP 1193`, async () => { const returnRawData = generateAllRawData([schemaElement], false); const provider = new HttpProvider({ returnData: returnRawData }, [ ERC725Y_INTERFACE_IDS.legacy, @@ -898,7 +898,7 @@ describe('Running @erc725/erc725.js tests...', () => { // ARRAY type: if (schemaElement.keyType.toLowerCase() === 'array') { - it('Encode data values in array: ' + schemaElement.name, async () => { + it(`Encode data values in array: ${schemaElement.name}`, async () => { const results: string[] = []; // Encode array loop @@ -922,7 +922,7 @@ describe('Running @erc725/erc725.js tests...', () => { assert.deepStrictEqual(results, schemaElement.returnGraphData); }); - it('decodes data values in array: ' + schemaElement.name, async () => { + it(`decodes data values in array: ${schemaElement.name}`, async () => { const results: any[] = []; // decode array loop @@ -1071,7 +1071,7 @@ describe('Running @erc725/erc725.js tests...', () => { } // SINGLETON type: This is not an array, assumed 'Singleton' - it('encodes data value for: ' + schemaElement.name, async () => { + it(`encodes data value for: ${schemaElement.name}`, async () => { const result = encodeKeyValue( schemaElement.valueContent, schemaElement.valueType, @@ -1081,7 +1081,7 @@ describe('Running @erc725/erc725.js tests...', () => { assert.deepStrictEqual(result, schemaElement.returnGraphData); }); - it('decodes data value for: ' + schemaElement.name, async () => { + it(`decodes data value for: ${schemaElement.name}`, async () => { const result = decodeKeyValue( schemaElement.valueContent, schemaElement.valueType, @@ -1397,7 +1397,7 @@ describe('Running @erc725/erc725.js tests...', () => { const erc725Instance = new ERC725([]); - describe(`encodePermissions`, () => { + describe('encodePermissions', () => { testCases.forEach((testCase) => { it(`Encodes ${testCase.hex} permission correctly`, () => { assert.deepStrictEqual( diff --git a/src/lib/decodeData.test.ts b/src/lib/decodeData.test.ts index 65845c33..f1e398ed 100644 --- a/src/lib/decodeData.test.ts +++ b/src/lib/decodeData.test.ts @@ -309,7 +309,7 @@ describe('tuple', () => { ]; // TODO: add more cases? Address, etc. testCases.forEach((testCase) => { - it(`decodes tuple values`, () => { + it('decodes tuple values', () => { expect( decodeTupleKeyValue( testCase.valueContent, @@ -348,19 +348,22 @@ describe('tuple', () => { { valueType: '(bytes4,bytes8)', valueContent: '(Bytes4,Number,Bytes5)', - isTuple: false, // valueContent length != valueType length + // valueContent length != valueType length + isTuple: false, shouldThrow: true, }, { valueType: '(bytes4,bytes8)', valueContent: '(Bytes2,Number)', - isTuple: false, // first item in valueType does not fit inside first item in valueContent (bytes4 > bytes2) + // first item in valueType does not fit inside first item in valueContent (bytes4 > bytes2) + isTuple: false, shouldThrow: true, }, { valueType: '(bytes4,bytes8)', valueContent: '(Bytes8,Number)', - isTuple: true, // first item in valueType fit in first item of valueContent (bytes4 < bytes8) + // first item in valueType fit in first item of valueContent (bytes4 < bytes8) + isTuple: true, }, { valueType: '(bytes4,bytes8)', diff --git a/src/lib/decodeData.ts b/src/lib/decodeData.ts index 360e35c1..cecb0bf8 100644 --- a/src/lib/decodeData.ts +++ b/src/lib/decodeData.ts @@ -113,7 +113,7 @@ export const isValidTuple = (valueType: string, valueContent: string) => { // is compatible with the valueType (e.g: bytes4) const hexLiteralLength = valueContentParts[i].length - 2; - if (parseInt(valueTypeBytesLength, 10) < hexLiteralLength) { + if (Number.parseInt(valueTypeBytesLength, 10) < hexLiteralLength) { throw new Error( `Invalid tuple (${valueType},${valueContent}: ${valueContent[i]} cannot fit in ${valueType[i]}`, ); @@ -148,11 +148,12 @@ export const decodeTupleKeyValue = ( const regexMatch = valueTypePart.match(tupleValueTypesRegex); // if we are dealing with `bytesN` - if (regexMatch) bytesLengths.push(parseInt(regexMatch[1], 10)); + if (regexMatch) bytesLengths.push(Number.parseInt(regexMatch[1], 10)); const numericMatch = valueTypePart.match(/u?int(\d+)/); - if (numericMatch) bytesLengths.push(parseInt(numericMatch[1], 10) / 8); + if (numericMatch) + bytesLengths.push(Number.parseInt(numericMatch[1], 10) / 8); if (valueTypePart === 'address') bytesLengths.push(20); }); @@ -289,9 +290,7 @@ export function decodeKey(schema: ERC725JSONSchema, value) { } default: { console.error( - 'Incorrect data match or keyType in schema from decodeKey(): "' + - schema.keyType + - '"', + `Incorrect data match or keyType in schema from decodeKey(): "${schema.keyType}"`, ); return null; } diff --git a/src/lib/decodeMappingKey.test.ts b/src/lib/decodeMappingKey.test.ts index 7f411ece..3f804b90 100644 --- a/src/lib/decodeMappingKey.test.ts +++ b/src/lib/decodeMappingKey.test.ts @@ -193,7 +193,7 @@ describe('decodeDynamicKeyParts', () => { '0x3234535343fXXWGWXWDSWDAEDFAEDr5434534grdgrdggrdgdrgdgrd098594334', 'MyKeyName:', ), - ).to.throw(`Invalid encodedKey, must be a hexadecimal value`); + ).to.throw('Invalid encodedKey, must be a hexadecimal value'); }); it('throws if incorrect length key', () => { @@ -203,7 +203,7 @@ describe('decodeDynamicKeyParts', () => { 'MyKeyName:', ), ).to.throw( - `Invalid encodedKey length, key must be 32 bytes long hexadecimal value`, + 'Invalid encodedKey length, key must be 32 bytes long hexadecimal value', ); }); }); diff --git a/src/lib/decodeMappingKey.ts b/src/lib/decodeMappingKey.ts index 4071e2c9..b4c17478 100644 --- a/src/lib/decodeMappingKey.ts +++ b/src/lib/decodeMappingKey.ts @@ -42,14 +42,15 @@ function decodeKeyPart( ): DynamicKeyPart | false { if (!isDynamicKeyPart(keyPartName)) return false; - let decodedKey; + let decodedKey: string | number | boolean | undefined; const type = keyPartName.slice(1, keyPartName.length - 1); if (type === 'bool') decodedKey = encodedKeyPart.slice(encodedKeyPart.length - 1) === '1'; - else if (type.includes('uint')) decodedKey = parseInt(encodedKeyPart, 16); + else if (type.includes('uint')) + decodedKey = Number.parseInt(encodedKeyPart, 16); else if (type.includes('bytes')) { - const bytesLength = parseInt(type.replace('bytes', ''), 10) * 2; + const bytesLength = Number.parseInt(type.replace('bytes', ''), 10) * 2; const sliceFrom = encodedKeyPart.length - bytesLength < 0 ? 0 @@ -57,14 +58,14 @@ function decodeKeyPart( decodedKey = encodedKeyPart.slice(sliceFrom); } else if (type === 'address') { // this is required if the 2nd word is an address in a MappingWithGrouping - const leftPaddedAddress = padLeft('0x' + encodedKeyPart, 40); + const leftPaddedAddress = padLeft(`0x${encodedKeyPart}`, 40); decodedKey = decodeValueType(type, leftPaddedAddress); } else { decodedKey = decodeValueType(type, encodedKeyPart); } - return { type, value: decodedKey }; + return { type, value: decodedKey as string | number | boolean }; } /** @@ -79,14 +80,14 @@ export function decodeMappingKey( ): DynamicKeyPart[] { let hashedKey = keyHash; if (hashedKey.length === 64 && hashedKey.slice(0, 2) !== '0x') - hashedKey = '0x' + hashedKey; + hashedKey = `0x${hashedKey}`; if (hashedKey.length !== 66) throw new Error( - `Invalid encodedKey length, key must be 32 bytes long hexadecimal value`, + 'Invalid encodedKey length, key must be 32 bytes long hexadecimal value', ); if (!isHex(hashedKey.slice(2))) - throw new Error(`Invalid encodedKey, must be a hexadecimal value`); + throw new Error('Invalid encodedKey, must be a hexadecimal value'); let keyParts: string[]; diff --git a/src/lib/encodeKeyName.ts b/src/lib/encodeKeyName.ts index 733146c6..24328a64 100644 --- a/src/lib/encodeKeyName.ts +++ b/src/lib/encodeKeyName.ts @@ -61,7 +61,7 @@ export const encodeDynamicKeyPart = ( // eslint-disable-next-line prefer-destructuring baseType = regexMatch[1]; - size = parseInt(regexMatch[2], 10); + size = Number.parseInt(regexMatch[2], 10); } switch (baseType) { diff --git a/src/lib/encoder.test.ts b/src/lib/encoder.test.ts index 3cc6dc8c..8ddf60d3 100644 --- a/src/lib/encoder.test.ts +++ b/src/lib/encoder.test.ts @@ -786,7 +786,7 @@ describe('encoder', () => { it('should throw when trying to encode a `bytes[CompactBytesArray]` with a bytes length bigger than 65_535', async () => { expect(() => { encodeValueType('bytes[CompactBytesArray]', [ - '0x' + 'ab'.repeat(66_0000), + `0x${'ab'.repeat(66_0000)}`, ]); }).to.throw( "Couldn't encode bytes[CompactBytesArray], value at index 0 exceeds 65_535 bytes", diff --git a/src/lib/encoder.ts b/src/lib/encoder.ts index 7092f3b6..300852c4 100644 --- a/src/lib/encoder.ts +++ b/src/lib/encoder.ts @@ -119,7 +119,7 @@ const decodeDataSourceWithHash = (value: string): URLDataWithHash => { const encodedLength = `0x${value.slice(14, 18)}`; // Rest of data string after function hash const dataLength = hexToNumber(encodedLength, false) as number; const dataHash = `0x${value.slice(18, 18 + dataLength * 2)}`; // Get jsonHash 32 bytes - const dataSource = hexToUtf8('0x' + value.slice(18 + dataLength * 2)); // Get remainder as URI + const dataSource = hexToUtf8(`0x${value.slice(18 + dataLength * 2)}`); // Get remainder as URI return { verification: { @@ -144,7 +144,7 @@ const decodeDataSourceWithHash = (value: string): URLDataWithHash => { // Special case where JSONURL is really (bytes4,URI) as specified // by the old version of LSP8TokenMetadataBaseURI // Catch error in case the buffor is not convertable to utf8. - const dataSource = hexToUtf8('0x' + encodedData); // Get as URI + const dataSource = hexToUtf8(`0x${encodedData}`); // Get as URI if (encodedData.length < 64 || /^[a-z]{2,}:[/\S]/.test(dataSource)) { // If the verification data starts with a utf8 sequence that looks like https:/ or data: or ar:/ for example. return { @@ -159,8 +159,8 @@ const decodeDataSourceWithHash = (value: string): URLDataWithHash => { // ignore } - const dataHash = '0x' + encodedData.slice(0, 64); // Get jsonHash 32 bytes - const dataSource = hexToUtf8('0x' + encodedData.slice(64)); // Get remainder as URI + const dataHash = `0x${encodedData.slice(0, 64)}`; // Get jsonHash 32 bytes + const dataSource = hexToUtf8(`0x${encodedData.slice(64)}`); // Get remainder as URI return { verification: { @@ -187,7 +187,7 @@ const encodeToBytesN = ( valueToEncode = value; } - const numberOfBytesInType = parseInt(bytesN.split('bytes')[1], 10); + const numberOfBytesInType = Number.parseInt(bytesN.split('bytes')[1], 10); const numberOfBytesInValue = countNumberOfBytes(valueToEncode); if (numberOfBytesInValue > numberOfBytesInType) { @@ -256,7 +256,7 @@ const decodeCompactBytesArray = (compactBytesArray: string): string[] => { while (pointer < strippedCompactBytesArray.length) { const length = Number( - hexToNumber('0x' + strippedCompactBytesArray.slice(pointer, pointer + 4)), + hexToNumber(`0x${strippedCompactBytesArray.slice(pointer, pointer + 4)}`), ); if (length === 0) { @@ -264,11 +264,10 @@ const decodeCompactBytesArray = (compactBytesArray: string): string[] => { encodedValues.push(''); } else { encodedValues.push( - '0x' + - strippedCompactBytesArray.slice( - pointer + 4, - pointer + 2 * (length + 2), - ), + `0x${strippedCompactBytesArray.slice( + pointer + 4, + pointer + 2 * (length + 2), + )}`, ); } @@ -444,7 +443,7 @@ const valueTypeEncodingMap = ( const uintNRegexMatch = type.match(uintNValueTypeRegex); const uintLength = uintNRegexMatch - ? parseInt(uintNRegexMatch[0].slice(4), 10) + ? Number.parseInt(uintNRegexMatch[0].slice(4), 10) : ''; if (type.includes('[CompactBytesArray]')) { @@ -604,7 +603,7 @@ const valueTypeEncodingMap = ( // we want to return an array of numbers as [1, 2, 3], not an array of strings as [ '1', '2', '3'] return abiCoder .decodeParameter('uint256[]', value) - .map((numberAsString) => parseInt(numberAsString, 10)); + .map((numberAsString) => Number.parseInt(numberAsString, 10)); }, }; case 'bytes32[]': @@ -661,7 +660,9 @@ export const valueContentEncodingMap = ( decode: (value: string) => any; } => { const bytesNRegexMatch = valueContent.match(BytesNValueContentRegex); - const bytesLength = bytesNRegexMatch ? parseInt(bytesNRegexMatch[1], 10) : ''; + const bytesLength = bytesNRegexMatch + ? Number.parseInt(bytesNRegexMatch[1], 10) + : ''; switch (valueContent) { case 'Keccak256': { @@ -677,7 +678,7 @@ export const valueContentEncodingMap = ( encode: (value: string) => { let parsedValue: number; try { - parsedValue = parseInt(value, 10); + parsedValue = Number.parseInt(value, 10); } catch (error: any) { throw new Error(error); } @@ -696,7 +697,7 @@ export const valueContentEncodingMap = ( return value.toLowerCase(); } - throw new Error('Address: "' + value + '" is an invalid address.'); + throw new Error(`Address: "${value}" is an invalid address.`); }, decode: (value: string) => toChecksumAddress(value), }; diff --git a/src/lib/getData.ts b/src/lib/getData.ts index acff7746..4d00f666 100644 --- a/src/lib/getData.ts +++ b/src/lib/getData.ts @@ -160,8 +160,9 @@ const getDataMultiple = async ( export const getData = async ( erc725Options: ERC725Options, - keyOrKeys?: GetDataInput, + _keyOrKeys?: GetDataInput, ): Promise => { + let keyOrKeys = _keyOrKeys; if (!keyOrKeys) { // eslint-disable-next-line no-param-reassign keyOrKeys = erc725Options.schemas diff --git a/src/lib/schemaParser.ts b/src/lib/schemaParser.ts index 2d7ae125..d2e94c52 100644 --- a/src/lib/schemaParser.ts +++ b/src/lib/schemaParser.ts @@ -74,7 +74,7 @@ const findArraySchemaForKey = ( return null; } - const elementIndex = parseInt(key.substring(34), 10); + const elementIndex = Number.parseInt(key.substring(34), 10); return { ...arraySchema, diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts index 27a75b2a..90212974 100644 --- a/src/lib/utils.test.ts +++ b/src/lib/utils.test.ts @@ -417,7 +417,7 @@ describe('utils', () => { ]; // we may need to add more test cases! Address, etc. testCases.forEach((testCase) => { - it(`encodes tuple values`, () => { + it('encodes tuple values', () => { expect( encodeTupleKeyValue( testCase.valueContent, diff --git a/test/mockProviders.ts b/test/mockProviders.ts index c57e725b..79d007c9 100644 --- a/test/mockProviders.ts +++ b/test/mockProviders.ts @@ -64,7 +64,7 @@ export class HttpProvider { { const foundResult = this.returnData.find((element) => { // get call param (key) - const keyParam = '0x' + payload[index].params[0].data.slice(10); + const keyParam = `0x${payload[index].params[0].data.slice(10)}`; return element.key === keyParam; }); @@ -143,7 +143,7 @@ export class HttpProvider { break; case METHODS[Method.GET_DATA_LEGACY].sig: { - const keyParam = '0x' + payload.params[0].data.slice(10); + const keyParam = `0x${payload.params[0].data.slice(10)}`; const foundResult = this.returnData.find((e) => e.key === keyParam); result = foundResult ? foundResult.value : '0x'; } @@ -151,7 +151,7 @@ export class HttpProvider { case METHODS[Method.GET_DATA_BATCH].sig: case METHODS[Method.GET_DATA].sig: { - const keyParam = '0x' + payload.params[0].data.slice(138); + const keyParam = `0x${payload.params[0].data.slice(138)}`; const foundResult = this.returnData.find((e) => e.key === keyParam); result = foundResult ? foundResult.value : '0x'; } @@ -224,7 +224,7 @@ export class EthereumProvider { break; case METHODS[Method.GET_DATA_LEGACY].sig: { - const keyParam = '0x' + payload.params[0].data.slice(10); + const keyParam = `0x${payload.params[0].data.slice(10)}`; result = this.returnData.find((e) => e.key === keyParam)?.value; } From 3fd66e374716e452799b00c045ec35eefd0299e3 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Thu, 11 Apr 2024 04:53:50 -0400 Subject: [PATCH 2/3] fix: Push a change --- src/lib/permissions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/permissions.ts b/src/lib/permissions.ts index 15647f5b..b35fb55e 100644 --- a/src/lib/permissions.ts +++ b/src/lib/permissions.ts @@ -63,6 +63,7 @@ export function decodePermissions(permissionHex: string) { // Do not use an for of loop here to not require the regenerator runtime // Deal with ALL_PERMISSIONS the same way. So as long as all the bits in ALL_PERMISSIONS + // are set the same way as in ALL_PERMISSIONS then this flag will return as true. // It does not mean some extra permissions are not included. for (let i = 0; i < permissionsToTest.length; i += 1) { From 82f6cfe297ea38b9e3bfe9d6f08cd0096cc19fbc Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Thu, 11 Apr 2024 05:00:52 -0400 Subject: [PATCH 3/3] fix: Remove eslint script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 82fe37cb..8a7746ea 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "build:main": "tsc -p tsconfig.json", "build:module": "tsc -p tsconfig.module.json", "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=text --reporter=lcov mocha", - "lint": "eslint . --ext .ts", + "lint": "biome check .", + "lint:fix": "biome check --apply .", "format:fix": "prettier --write .", "format": "prettier .", "release": "standard-version"