Skip to content

Commit

Permalink
chore(contracts): Add solhint-plugin-prettier and tweak yarn scripts
Browse files Browse the repository at this point in the history
This commit adds solhint-plugin-prettier which allows us to use both solhint and prettier
on our solidity files, by ensure that solhint will throw an error when code is not formatted
according to prettier rules. It also makes some slight modifications to yarn scripts which
allows better separation between linting ts and solidity during CI runs
  • Loading branch information
maurelian authored and smartcontracts committed Nov 10, 2021
1 parent a6ef1a3 commit 634b2c5
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ts-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
run: yarn install

- name: Lint JS and TS
run: yarn lint:check
run: yarn lint:ts:check

- name: Lint Solidity
working-directory: ./packages/contracts
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"patch-package": "^6.4.7",
"prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.18",
"solhint-plugin-prettier": "^0.0.5",
"typescript": "^4.3.5"
},
"scripts": {
Expand All @@ -45,6 +46,7 @@
"test": "yarn lerna run test --parallel",
"test:coverage": "yarn lerna run test:coverage --parallel",
"lint": "yarn lerna run lint",
"lint:ts:check": "yarn lerna run lint:ts:check",
"lint:check": "yarn lerna run lint:check",
"lint:fix": "yarn lerna run lint:fix --parallel",
"postinstall": "patch-package",
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# WETH9 is a standard we should not modify it.
contracts/L2/predeploys/WETH9.sol
contracts/L2/predeploys/IWETH9.sol
5 changes: 3 additions & 2 deletions packages/contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"compiler-version": "off",
"code-complexity": ["warn", 5],
"max-line-length": ["error", 100],
Expand Down
4 changes: 4 additions & 0 deletions packages/contracts/.solhintignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules

# WETH9 is a standard we should not modify it.
contracts/L2/predeploys/WETH9.sol
contracts/L2/predeploys/IWETH9.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ contract OVM_DeployerWhitelist {
*/
function setOwner(address _owner) public onlyOwner {
// Prevent users from setting the whitelist owner to address(0) except via
// enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to any
// other address that doesn't have a corresponding knowable private key.
// enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to
// any other address that doesn't have a corresponding knowable private key.
require(
_owner != address(0),
"OVM_DeployerWhitelist: whitelist can only be disabled via enableArbitraryContractDeployment"
"OVM_DeployerWhitelist: can only be disabled via enableArbitraryContractDeployment"
);

emit OwnerChanged(owner, _owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ contract OVM_GasPriceOracle is Ownable {
return scaled;
}

// solhint-disable max-line-length
/**
* Computes the amount of L1 gas used for a transaction
* The overhead represents the per batch gas overhead of
Expand All @@ -139,6 +140,7 @@ contract OVM_GasPriceOracle is Ownable {
* @param _data Unsigned RLP encoded tx, 6 elements
* @return Amount of L1 gas used for a transaction
*/
// solhint-enable max-line-length
function getL1GasUsed(bytes memory _data) public view returns (uint256) {
uint256 total = 0;
for (uint256 i = 0; i < _data.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ pragma solidity ^0.8.9;
* @title Lib_PredeployAddresses
*/
library Lib_PredeployAddresses {
// solhint-disable max-line-length
address internal constant L2_TO_L1_MESSAGE_PASSER = 0x4200000000000000000000000000000000000000;
address internal constant L1_MESSAGE_SENDER = 0x4200000000000000000000000000000000000001;
address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002;
address payable internal constant OVM_ETH = payable(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000);
// solhint-disable-next-line max-line-length
address internal constant L2_CROSS_DOMAIN_MESSENGER =
0x4200000000000000000000000000000000000007;
address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008;
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"test:slither": "slither .",
"pretest:slither": "rm -f @openzeppelin && rm -f @ens && rm -f hardhat && ln -s ../../node_modules/@openzeppelin @openzeppelin && ln -s ../../node_modules/@ens @ens && ln -s ../../node_modules/hardhat hardhat",
"posttest:slither": "rm -f @openzeppelin && rm -f @ens && rm -f hardhat",
"lint:typescript:check": "eslint .",
"lint:ts:check": "eslint .",
"lint:contracts:check": "yarn solhint -f table 'contracts/**/*.sol'",
"lint:check": "yarn lint:contracts:check && yarn lint:typescript:check",
"lint:check": "yarn lint:contracts:check && yarn lint:ts:check",
"lint": "yarn lint:check",
"lint:typescript:fix": "eslint --fix .",
"lint:ts:fix": "eslint --fix .",
"lint:contracts:fix": "yarn prettier --write 'contracts/**/*.sol'",
"lint:fix": "yarn lint:contracts:fix && yarn lint:typescript:fix",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"clean": "rm -rf ./dist ./artifacts ./cache ./tsconfig.build.tsbuildinfo",
"deploy": "ts-node bin/deploy.ts && yarn autogen:markdown",
"prepublishOnly": "yarn copyfiles -u 1 -e \"**/test-*/**/*\" \"contracts/**/*\" ./",
Expand Down
Loading

0 comments on commit 634b2c5

Please sign in to comment.