Skip to content

Commit 1471dbd

Browse files
authored
feat: added standard Eslint ruling for codebase source files (#50)
* feat: eslint ruling * feat: prettier config * feat: vscode workspace settings for auto formatting on save * feat: test & format scripts * refactor: eslint formatting on source files * chore: package json & minors * fix: couldn't find the plugin "eslint-plugin-prettier"
1 parent d7a3ca1 commit 1471dbd

19 files changed

+697
-311
lines changed

.eslintrc.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,28 @@
44
"commonjs": true,
55
"es2021": true
66
},
7-
"extends": "standard-with-typescript",
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11+
"plugin:prettier/recommended",
12+
"standard-with-typescript",
13+
"prettier"
14+
],
15+
"parser": "@typescript-eslint/parser",
816
"parserOptions": {
917
"ecmaVersion": "latest",
1018
"project": "./tsconfig.json"
1119
},
12-
"rules": {}
20+
"plugins": ["@typescript-eslint"],
21+
"rules": {
22+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
23+
"@typescript-eslint/explicit-function-return-type": "error",
24+
"@typescript-eslint/no-explicit-any": "error",
25+
"@typescript-eslint/no-non-null-assertion": "error",
26+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
27+
"@typescript-eslint/prefer-nullish-coalescing": "error",
28+
"@typescript-eslint/prefer-optional-chain": "error",
29+
"prettier/prettier": ["error", { "singleQuote": true, "trailingComma": "none", "tabWidth": 4 }]
30+
}
1331
}

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"tabWidth": 4
5+
}

.vscode/settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"eslint.format.enable": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
},
6+
"[typescriptreact]": {
7+
"editor.defaultFormatter": "esbenp.prettier-vscode"
8+
},
9+
"[typescript]": {
10+
"editor.defaultFormatter": "vscode.typescript-language-features"
11+
},
12+
"window.zoomLevel": 0,
13+
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"postinstall": "husky install",
1111
"build": "turbo build",
1212
"lint": "turbo lint",
13-
"test": "turbo test"
13+
"test": "turbo test",
14+
"format": "turbo format"
1415
},
1516
"private": true,
1617
"workspaces": [

packages/core/package.json

+33-28
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
{
2-
"name": "core",
3-
"version": "1.0.0",
4-
"main": "index.js",
5-
"license": "MIT",
6-
"scripts": {
7-
"build": "rm -rf ./dist && tsup src/index.ts --format cjs,esm --dts",
8-
"lint": "eslint --ext .ts src --ext .ts tests",
9-
"test": "rm -rf ./coverage && jest --coverage"
10-
},
11-
"devDependencies": {
12-
"@jest/globals": "^29.7.0",
13-
"@typescript-eslint/eslint-plugin": "^6.7.2",
14-
"eslint": "^8.0.1",
15-
"eslint-config-standard-with-typescript": "^39.0.0",
16-
"eslint-plugin-import": "^2.25.2",
17-
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
18-
"eslint-plugin-promise": "^6.0.0",
19-
"jest": "^29.7.0",
20-
"ts-jest": "^29.1.1",
21-
"tsup": "^7.2.0",
22-
"typescript": "*"
23-
},
24-
"dependencies": {
25-
"@noble/secp256k1": "^2.0.0",
26-
"blakejs": "^1.2.1",
27-
"elliptic": "^6.5.4",
28-
"ethers": "^6.7.1"
29-
}
2+
"name": "core",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"build": "rm -rf ./dist && tsup src/index.ts --format cjs,esm --dts",
8+
"lint": "eslint --ext .ts src --ext .ts tests",
9+
"test": "rm -rf ./coverage && jest --coverage",
10+
"format": "prettier --write src/**/*.ts tests/**/*.ts"
11+
},
12+
"devDependencies": {
13+
"@jest/globals": "^29.7.0",
14+
"@typescript-eslint/eslint-plugin": "^6.7.2",
15+
"eslint": "^8.0.1",
16+
"eslint-config-prettier": "^9.0.0",
17+
"eslint-config-standard-with-typescript": "^39.0.0",
18+
"eslint-plugin-import": "^2.25.2",
19+
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
20+
"eslint-plugin-prettier": "^5.0.0",
21+
"eslint-plugin-promise": "^6.0.0",
22+
"jest": "^29.7.0",
23+
"prettier": "^3.0.3",
24+
"ts-jest": "^29.1.1",
25+
"tsup": "^7.2.0",
26+
"typescript": "*"
27+
},
28+
"dependencies": {
29+
"@noble/secp256k1": "^2.0.0",
30+
"@types/elliptic": "^6.4.15",
31+
"blakejs": "^1.2.1",
32+
"elliptic": "^6.5.4",
33+
"ethers": "^6.7.1"
34+
}
3035
}

packages/core/src/hash/blake2b256.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import blake from 'blakejs'
2-
import { type ethers } from 'ethers'
1+
import blake from 'blakejs';
2+
import { type ethers } from 'ethers';
33

44
/**
55
* computes blake2b 256bit hash of given data
66
* @param data one or more Buffer | string
77
*/
8-
function blake2b256 (data: ethers.BytesLike): string {
9-
// Convert BytesLike to Buffer
10-
const dataBytesLike = [data] as Array<Buffer | string>
8+
function blake2b256(data: ethers.BytesLike): string {
9+
// Convert BytesLike to Buffer
10+
const dataBytesLike = [data] as Array<Buffer | string>;
1111

12-
// Apply blake2b256 hash on buffer
13-
const ctx = blake.blake2bInit(32)
14-
dataBytesLike.forEach(d => {
15-
if (Buffer.isBuffer(d)) {
16-
blake.blake2bUpdate(ctx, d)
17-
} else {
18-
blake.blake2bUpdate(ctx, Buffer.from(d, 'utf8'))
19-
}
20-
})
21-
return `0x${Buffer.from(blake.blake2bFinal(ctx)).toString('hex')}`
12+
// Apply blake2b256 hash on buffer
13+
const ctx = blake.blake2bInit(32);
14+
dataBytesLike.forEach((d) => {
15+
if (Buffer.isBuffer(d)) {
16+
blake.blake2bUpdate(ctx, d);
17+
} else {
18+
blake.blake2bUpdate(ctx, Buffer.from(d, 'utf8'));
19+
}
20+
});
21+
return `0x${Buffer.from(blake.blake2bFinal(ctx)).toString('hex')}`;
2222
}
2323

24-
export { blake2b256 }
24+
export { blake2b256 };

packages/core/src/hash/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from '.'
1+
export * from '.';

packages/core/src/hash/keccak256.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethers } from 'ethers'
1+
import { ethers } from 'ethers';
22

33
/**
44
* keccak256 hash function implementation.
@@ -7,12 +7,14 @@ import { ethers } from 'ethers'
77
* @param data Data to hash
88
* @returns Hash of data
99
*/
10-
function keccak256 (data: ethers.BytesLike): string {
11-
// Data is not bytes-like
12-
if (ethers.isBytesLike(data)) { return ethers.keccak256(data) }
10+
function keccak256(data: ethers.BytesLike): string {
11+
// Data is not bytes-like
12+
if (ethers.isBytesLike(data)) {
13+
return ethers.keccak256(data);
14+
}
1315

14-
// Data is string
15-
return ethers.keccak256(ethers.toUtf8Bytes(data))
16+
// Data is string
17+
return ethers.keccak256(ethers.toUtf8Bytes(data));
1618
}
1719

18-
export { keccak256 }
20+
export { keccak256 };

packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('Hello from core package')
1+
console.log('Hello from core package');

packages/core/src/secp256k1/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from '.'
1+
export * from '.';

0 commit comments

Comments
 (0)