Skip to content

Commit d85462c

Browse files
committed
Adding code formatter and static code analyzer
- Added linters for TS/JS - Added prettier for JSON/YAML - Added sol linters - Added pre commit hooks
1 parent f297202 commit d85462c

15 files changed

+1285
-282
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ yarn-error.log
4949

5050
# Hardhat
5151
cache/
52-
export.json
52+
export.json
53+
solidity/random-beacon/typechain

.pre-commit-config.yaml

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ repos:
1717
files: '\.sol$'
1818
language: script
1919
description: "Checks solidity code according to the package's linter configuration"
20-
- id: lint-js
21-
name: 'lint solidity js'
22-
entry: /usr/bin/env bash -c "cd solidity-v1 && npm run lint:js"
23-
files: 'solidity-v1\/.*\.js$'
20+
- id: lint-eslint
21+
name: 'lint solidity ts/js'
22+
entry: /usr/bin/env bash -c "cd solidity/random-beacon && npm run lint:eslint"
23+
files: 'solidity/random-beacon\/.*'
2424
language: script
25-
description: "Checks JS code according to the package's linter configuration"
25+
description: "Checks TS/JS code according to the package's linter configuration"
26+
- id: lint-config
27+
name: 'lint solidity json/yaml'
28+
entry: /usr/bin/env bash -c "cd solidity/random-beacon && npm run lint:config"
29+
files: 'solidity/random-beacon\/.*'
30+
language: script
31+
description: "Checks JSON/YAML code according to the package's linter configuration"
2632
- id: format-dashboard
2733
name: 'format dashboard'
2834
entry: /usr/bin/env bash -c "cd solidity-v1/dashboard && npm run format"

solidity/random-beacon/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

solidity/random-beacon/.eslintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"root": true,
3+
"extends": ["@thesis-co"],
4+
"parserOptions": {
5+
"ecmaVersion": 2017,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"es6": true,
10+
"mocha": true
11+
},
12+
"rules": {
13+
"new-cap": "off"
14+
}
15+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
artifacts/
2+
build/
3+
cache/
4+
deployments/
5+
export.json
6+
typechain/

solidity/random-beacon/.solhint.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "keep",
3+
"plugins": [],
4+
"rules": {
5+
"func-visibility": ["error", { "ignoreConstructors": true }]
6+
}
7+
}

solidity/random-beacon/.solhintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./node_modules/@thesis-co/eslint-config/.tsconfig-eslint.json

solidity/random-beacon/contracts/test/TestToken.sol

-9
This file was deleted.

solidity/random-beacon/deploy/00_deploy_test_token.ts

-25
This file was deleted.

solidity/random-beacon/hardhat.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import "@tenderly/hardhat-tenderly"
77
import "@nomiclabs/hardhat-waffle"
88
import "hardhat-gas-reporter"
99
import "hardhat-contract-sizer"
10+
import "@typechain/hardhat"
11+
import "@nomiclabs/hardhat-ethers"
1012

1113
const config: HardhatUserConfig = {
1214
solidity: {
@@ -33,7 +35,7 @@ const config: HardhatUserConfig = {
3335
url: process.env.FORKING_URL || "",
3436
// latest block is taken if FORKING_BLOCK env is not provided
3537
blockNumber: process.env.FORKING_BLOCK
36-
? parseInt(process.env.FORKING_BLOCK)
38+
? parseInt(process.env.FORKING_BLOCK, 10)
3739
: undefined,
3840
},
3941
tags: ["local"],

solidity/random-beacon/package.json

+29-11
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,50 @@
55
"scripts": {
66
"build": "hardhat compile",
77
"test": "hardhat test",
8-
"deploy": "hardhat deploy --export export.json"
8+
"deploy": "hardhat deploy --export export.json",
9+
"format": "npm run lint",
10+
"format:fix": "npm run lint:fix",
11+
"lint": "npm run lint:eslint && npm run lint:sol && npm run lint:config",
12+
"lint:fix": "npm run lint:fix:eslint && npm run lint:fix:sol && npm run lint:config:fix",
13+
"lint:eslint": "eslint .",
14+
"lint:fix:eslint": "eslint . --fix",
15+
"lint:sol": "solhint 'contracts/**/*.sol'",
16+
"lint:fix:sol": "solhint 'contracts/**/*.sol' --fix",
17+
"lint:config": "prettier -c '**/*.@(json|yaml)'",
18+
"lint:config:fix": "prettier -w '**/*.@(json|yaml)'"
919
},
1020
"dependencies": {
1121
"@openzeppelin/contracts": "^4.3.2",
12-
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf"
13-
},
14-
"devDependencies": {
22+
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf",
23+
"hardhat": "^2.6.4",
24+
"hardhat-deploy": "^0.9.1",
1525
"@keep-network/hardhat-helpers": "https://github.com/keep-network/hardhat-helpers#ed35ab7",
1626
"@keep-network/hardhat-local-networks-config": "^0.1.0-pre.0",
1727
"@nomiclabs/hardhat-ethers": "^2.0.2",
1828
"@nomiclabs/hardhat-waffle": "^2.0.1",
1929
"@tenderly/hardhat-tenderly": "^1.0.12",
30+
"@typechain/hardhat": "^2.3.0",
31+
"hardhat-gas-reporter": "^1.0.4",
32+
"hardhat-contract-sizer": "^2.1.1"
33+
},
34+
"devDependencies": {
2035
"@types/chai": "^4.2.22",
2136
"@types/mocha": "^9.0.0",
2237
"@types/node": "^16.9.6",
2338
"chai": "^4.3.4",
24-
"eslint": "^7.30.0",
25-
"eslint-config-keep": "github:keep-network/eslint-config-keep#0c27ade",
39+
"eslint": "^7.2.0",
40+
"eslint-plugin-import": "^2.18.2",
2641
"ethereum-waffle": "^3.4.0",
2742
"ethers": "^5.4.7",
28-
"hardhat": "^2.6.4",
29-
"hardhat-contract-sizer": "^2.1.1",
30-
"hardhat-deploy": "^0.9.1",
31-
"hardhat-gas-reporter": "^1.0.4",
43+
"@thesis-co/eslint-config": "github:thesis/eslint-config",
44+
"@typechain/ethers-v5": "^7.1.2",
45+
"solhint": "^3.3.6",
46+
"solhint-config-keep": "github:keep-network/solhint-config-keep",
3247
"ts-node": "^10.2.1",
33-
"typescript": "^4.4.3"
48+
"typechain": "^5.1.2",
49+
"typescript": "^4.4.3",
50+
"prettier": "^2.4.1",
51+
"prettier-plugin-solidity": "^1.0.0-beta.18"
3452
},
3553
"engines": {
3654
"node": ">= 14.0.0"

solidity/random-beacon/test/TestToken.test.ts

-18
This file was deleted.

solidity/random-beacon/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"./hardhat.config.ts",
44
"node_modules/@keep-network/hardhat-local-networks-config/src/type-extensions.d.ts"
55
],
6-
"include": ["./deploy", "./test"]
6+
"include": ["./deploy", "./test", "./typechain"]
77
}

0 commit comments

Comments
 (0)