-
Notifications
You must be signed in to change notification settings - Fork 4
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
Setting up HH framework for Litmus Core development #1
Conversation
dimpar
commented
Oct 19, 2023
- Added new hh toolbox
- Added deployemnt plugin
- Added helper scripts
- Added linters
- Added placeholder dirs for contracts and tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥:fire::fire:
The first round of comments.
core/test/Litmus.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about naming the file Litmus.test.ts
to establish the ContractName.test.ts
convention?
core/scripts/deploy.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename the directory to deploy
and rename the file to 01_deploy_litmus.ts
.
core/.eslintrc
Outdated
{ | ||
"root": true, | ||
"extends": ["@thesis-co"], | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"new-cap": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we keep the configuration here minimal and see what we can pull from https://github.com/keep-network/keep-core/blob/main/solidity/ecdsa/.eslintrc to the common @thesis-co
rules?
{ | |
"root": true, | |
"extends": ["@thesis-co"], | |
"parserOptions": { | |
"ecmaVersion": 2017, | |
"sourceType": "module" | |
}, | |
"env": { | |
"es6": true, | |
"mocha": true | |
}, | |
"rules": { | |
"new-cap": "off", | |
"import/no-extraneous-dependencies": "off", | |
"@typescript-eslint/no-use-before-define": "off", | |
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }] | |
} | |
} | |
{ | |
"root": true, | |
"extends": ["@thesis-co"] | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but e.g. this rule "import/no-extraneous-dependencies": "off"
has to stay, otherwise we get errors that some of the dependencies in package.json
are in devDependencies
instead of being in dependencies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, makes perfect sense! Could we disable it here only for specific files?
"import/no-extraneous-dependencies": [
"error",
{ devDependencies: ["hardhat.config.ts", "test/**"] },
],
core/package.json
Outdated
"@nomicfoundation/hardhat-verify": "^1.0.0", | ||
"@nomiclabs/hardhat-etherscan": "^3.1.7", | ||
"@nomiclabs/hardhat-waffle": "^2.0.6", | ||
"@openzeppelin/hardhat-upgrades": "^2.3.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this dependency until we really need it.
"@openzeppelin/hardhat-upgrades": "^2.3.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dimpar can we remove this dependency?
core/package.json
Outdated
"lint:eslint": "eslint .", | ||
"lint:fix:eslint": "eslint . --fix", | ||
"lint:sol": "solhint 'contracts/**/*.sol'", | ||
"lint:fix:sol": "solhint 'contracts/**/*.sol' --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards adding :fix
as a suffix for the scripts, as it seams cleaner on the list.
"lint:eslint": "eslint .", | |
"lint:fix:eslint": "eslint . --fix", | |
"lint:sol": "solhint 'contracts/**/*.sol'", | |
"lint:fix:sol": "solhint 'contracts/**/*.sol' --fix", | |
"lint:eslint": "eslint .", | |
"lint:eslint:fix": "eslint . --fix", | |
"lint:sol": "solhint 'contracts/**/*.sol'", | |
"lint:sol:fix": "solhint 'contracts/**/*.sol' --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, and I would simplify this structure a bit as well. See e.g.
"lint:eslint": "eslint .",
the key is longer than the value itself. I know there's a pattern, but having command just like yarn eslint
is a very straightforward too IMO.
I changed to the following:
"format": "npm run eslint && npm run solhint && npm run prettier:config",
"format:fix": "npm run eslint:fix && npm run solhint:fix && npm run prettier:config:fix",
"eslint": "eslint .",
"eslint:fix": "eslint . --fix",
"solhint": "solhint 'contracts/**/*.sol' && prettier --check 'contracts/**/*.sol'",
"solhint:fix": "solhint 'contracts/**/*.sol' --fix && prettier --write 'contracts/**/*.sol'",
"prettier:config": "prettier --check '**/*.@(json)'",
"prettier:config:fix": "prettier --write '**/*.@(json)'",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we hide the tool name in the script name? IMO we should be generic. If we changed the linting tool, we wouldn't have to change script name in package.json
in the future. I know it's a rather unlikely case but who knows 😆.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r-czajkowski made a good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, agree, making it generic makes sense, although once they are set I don't think we'll ever change them. They served us well in other projects.
Anyway, lint:fix:eslint
points to a concrete tool. lint:js
like in the comment here implies that it's for JavaScript. But we might as well use it for TypeScript. I'd propose simply leaving it as lint
and lint:fix
for all the JS/TS/JSX files, and add extensions like lint:sol
or lint:config
in all other cases. cc73eca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With lint:js
I think about the group of all file types from the JavaScript family (including *.js
, *.ts
, *.jsx
, *.cjs
), not about a specific extension.
I think it would be consistent to define lint:js
, as we have lint:sol
for all Solidity files, and lint:config
for JSON and YAML files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but lint:js
implies JavaScript. Ok, if you feel strongly about lint:js
I can change it. Consistency also comes with just having lint
at the front.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards lint:js
, would it be acceptable to you? 🙏🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments to take a look at before the merge.
core/.eslintrc
Outdated
"root": true, | ||
"extends": ["@thesis-co"], | ||
"rules": { | ||
"import/no-extraneous-dependencies": "off" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"import/no-extraneous-dependencies": "off" | |
"import/no-extraneous-dependencies": [ | |
"error", | |
{ devDependencies: ["hardhat.config.ts", "test/**"] }, | |
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you want to limit it to ["hardhat.config.ts", "test/**"]
only? This rule says that if e.g. "@nomicfoundation/hardhat-toolbox" is imported in other files than specified above then throw an error. We are not going to put "@nomicfoundation/hardhat-toolbox" under dependencies
in package.json
just because of some other file imports it. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set the import/no-extraneous-dependencies
to off
, we disable the check completely. But we want to have it.
With the configuration I proposed, the rule will be modified only for devDependencies
check in the files ["hardhat.config.ts", "test/**"]
. All other files will be verified according to the default behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I know, that's my point. Say we use import @nomicfoundation/hardhat-toolbox
in a file other than ["hardhat.config.ts", "test/**"]
and boom we have an error, because @nomicfoundation/hardhat-toolbox
in under devDependencies
and eslint wants it under dependencies
. We will need to add a new file to this array again. Is your point having it enabled only for specific files because in case we add a new lib in a wrong "dependencies" key in package.json you want to see an error? If yes, I can buy that, but at the same time it leaves the problem described at the beginning. I guess we need to chose less evil. Having said that, you still prefer having this enabled only for certain files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your point having it enabled only for specific files because in case we add a new lib in a wrong "dependencies" key in package.json you want to see an error?
Yes, exactly that. I don't want to have the dependencies we use in deployment script and tests to be pulled with dependencies
with the package. dependencies
should be only contracts dependencies, while all tests and scripts should be devDependencies
.
core/.solhint.json
Outdated
@@ -0,0 +1,7 @@ | |||
{ | |||
"extends": "keep", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forked the solhint config under thesis organization: thesis/solhint-config#1.
We don't need to switch in this PR, but flagging it for the future.
core/.solhint.json
Outdated
"extends": "keep", | ||
"plugins": [], | ||
"rules": { | ||
"func-visibility": ["error", { "ignoreConstructors": true }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't need to define this rule after thesis/solhint-config#2 is merged.
- Added new hh toolbox - Added deployemnt plugin - Added helper scripts - Added linters - Added placeholder dirs for contracts and tests
There are a lot of minor changes to include each in seperate commits. This is a part of the overall project structure. Changes include: - established pattern for the deployment scripts and testing files - cleanup in the package.json and hardhat.config.js - cleanup in prettier, eslint, slither and mocha config files - cleanup in gitignore
In this PR we add: - New HardHat toolbox - Deployment plugin - Helper scripts - Linters for JavaScript-like files, Solidity and JSON - Placeholder directories for contracts and tests This PR cherry picked all of the commits from #1 because of some rebasing issues that auto-closed that PR. I've tried a couple of resurrecting commands but they didn't help unfortunately. Most of the code was reviewed in that closed PR. The last reviewed commit was `3c4336e` and 2 commits were added since then addressing some of the review comments.
Continued in #7. |