Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch to biome #410

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"enabled": false
},
"files": {
"ignore": ["node_modules", "build", "coverage", ".vscode"]
"ignore": ["node_modules", ".nyc_output", "build", "coverage", ".vscode"]
}
}
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"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",
"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"
Expand All @@ -24,11 +21,7 @@
"type": "git",
"url": "git+https://github.com/ERC725Alliance/erc725.js"
},
"keywords": [
"ethereum",
"erc725",
"lsp"
],
"keywords": ["ethereum", "erc725", "lsp"],
"contributors": [
{
"name": "Robert McLeod",
Expand Down
52 changes: 26 additions & 26 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
14 changes: 7 additions & 7 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions src/lib/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)',
Expand Down
11 changes: 5 additions & 6 deletions src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`,
);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/decodeMappingKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('decodeDynamicKeyParts', () => {
'0x3234535343fXXWGWXWDSWDAEDFAEDr5434534grdgrdggrdgdrgdgrd098594334',
'MyKeyName:<bool>',
),
).to.throw(`Invalid encodedKey, must be a hexadecimal value`);
).to.throw('Invalid encodedKey, must be a hexadecimal value');
});

it('throws if incorrect length key', () => {
Expand All @@ -203,7 +203,7 @@ describe('decodeDynamicKeyParts', () => {
'MyKeyName:<bool>',
),
).to.throw(
`Invalid encodedKey length, key must be 32 bytes long hexadecimal value`,
'Invalid encodedKey length, key must be 32 bytes long hexadecimal value',
);
});
});
17 changes: 9 additions & 8 deletions src/lib/decodeMappingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,30 @@ 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
: encodedKeyPart.length - bytesLength;
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 };
}

/**
Expand All @@ -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[];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/encodeKeyName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading
Loading