Commit 634b2c54 authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

chore(contracts): Add solhint-plugin-prettier and tweak yarn scripts

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
parent a6ef1a3f
...@@ -159,7 +159,7 @@ jobs: ...@@ -159,7 +159,7 @@ jobs:
run: yarn install run: yarn install
- name: Lint JS and TS - name: Lint JS and TS
run: yarn lint:check run: yarn lint:ts:check
- name: Lint Solidity - name: Lint Solidity
working-directory: ./packages/contracts working-directory: ./packages/contracts
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
"patch-package": "^6.4.7", "patch-package": "^6.4.7",
"prettier": "^2.3.1", "prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.18", "prettier-plugin-solidity": "^1.0.0-beta.18",
"solhint-plugin-prettier": "^0.0.5",
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },
"scripts": { "scripts": {
...@@ -45,6 +46,7 @@ ...@@ -45,6 +46,7 @@
"test": "yarn lerna run test --parallel", "test": "yarn lerna run test --parallel",
"test:coverage": "yarn lerna run test:coverage --parallel", "test:coverage": "yarn lerna run test:coverage --parallel",
"lint": "yarn lerna run lint", "lint": "yarn lerna run lint",
"lint:ts:check": "yarn lerna run lint:ts:check",
"lint:check": "yarn lerna run lint:check", "lint:check": "yarn lerna run lint:check",
"lint:fix": "yarn lerna run lint:fix --parallel", "lint:fix": "yarn lerna run lint:fix --parallel",
"postinstall": "patch-package", "postinstall": "patch-package",
......
# WETH9 is a standard we should not modify it.
contracts/L2/predeploys/WETH9.sol contracts/L2/predeploys/WETH9.sol
contracts/L2/predeploys/IWETH9.sol contracts/L2/predeploys/IWETH9.sol
{ {
"extends": "solhint:recommended", "extends": "solhint:recommended",
"plugins": [], "plugins": ["prettier"],
"rules": { "rules": {
"prettier/prettier": "error",
"compiler-version": "off", "compiler-version": "off",
"code-complexity": ["warn", 5], "code-complexity": ["warn", 5],
"max-line-length": ["error", 100], "max-line-length": ["error", 100],
......
node_modules node_modules
# WETH9 is a standard we should not modify it.
contracts/L2/predeploys/WETH9.sol
contracts/L2/predeploys/IWETH9.sol
...@@ -57,11 +57,11 @@ contract OVM_DeployerWhitelist { ...@@ -57,11 +57,11 @@ contract OVM_DeployerWhitelist {
*/ */
function setOwner(address _owner) public onlyOwner { function setOwner(address _owner) public onlyOwner {
// Prevent users from setting the whitelist owner to address(0) except via // 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 // enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to
// other address that doesn't have a corresponding knowable private key. // any other address that doesn't have a corresponding knowable private key.
require( require(
_owner != address(0), _owner != address(0),
"OVM_DeployerWhitelist: whitelist can only be disabled via enableArbitraryContractDeployment" "OVM_DeployerWhitelist: can only be disabled via enableArbitraryContractDeployment"
); );
emit OwnerChanged(owner, _owner); emit OwnerChanged(owner, _owner);
......
...@@ -117,6 +117,7 @@ contract OVM_GasPriceOracle is Ownable { ...@@ -117,6 +117,7 @@ contract OVM_GasPriceOracle is Ownable {
return scaled; return scaled;
} }
// solhint-disable max-line-length
/** /**
* Computes the amount of L1 gas used for a transaction * Computes the amount of L1 gas used for a transaction
* The overhead represents the per batch gas overhead of * The overhead represents the per batch gas overhead of
...@@ -139,6 +140,7 @@ contract OVM_GasPriceOracle is Ownable { ...@@ -139,6 +140,7 @@ contract OVM_GasPriceOracle is Ownable {
* @param _data Unsigned RLP encoded tx, 6 elements * @param _data Unsigned RLP encoded tx, 6 elements
* @return Amount of L1 gas used for a transaction * @return Amount of L1 gas used for a transaction
*/ */
// solhint-enable max-line-length
function getL1GasUsed(bytes memory _data) public view returns (uint256) { function getL1GasUsed(bytes memory _data) public view returns (uint256) {
uint256 total = 0; uint256 total = 0;
for (uint256 i = 0; i < _data.length; i++) { for (uint256 i = 0; i < _data.length; i++) {
......
...@@ -5,12 +5,10 @@ pragma solidity ^0.8.9; ...@@ -5,12 +5,10 @@ pragma solidity ^0.8.9;
* @title Lib_PredeployAddresses * @title Lib_PredeployAddresses
*/ */
library Lib_PredeployAddresses { library Lib_PredeployAddresses {
// solhint-disable max-line-length
address internal constant L2_TO_L1_MESSAGE_PASSER = 0x4200000000000000000000000000000000000000; address internal constant L2_TO_L1_MESSAGE_PASSER = 0x4200000000000000000000000000000000000000;
address internal constant L1_MESSAGE_SENDER = 0x4200000000000000000000000000000000000001; address internal constant L1_MESSAGE_SENDER = 0x4200000000000000000000000000000000000001;
address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002; address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002;
address payable internal constant OVM_ETH = payable(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000); address payable internal constant OVM_ETH = payable(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000);
// solhint-disable-next-line max-line-length
address internal constant L2_CROSS_DOMAIN_MESSENGER = address internal constant L2_CROSS_DOMAIN_MESSENGER =
0x4200000000000000000000000000000000000007; 0x4200000000000000000000000000000000000007;
address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008; address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008;
......
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
"test:slither": "slither .", "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", "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", "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: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": "yarn lint:check",
"lint:typescript:fix": "eslint --fix .", "lint:ts:fix": "eslint --fix .",
"lint:contracts:fix": "yarn prettier --write 'contracts/**/*.sol'", "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", "clean": "rm -rf ./dist ./artifacts ./cache ./tsconfig.build.tsbuildinfo",
"deploy": "ts-node bin/deploy.ts && yarn autogen:markdown", "deploy": "ts-node bin/deploy.ts && yarn autogen:markdown",
"prepublishOnly": "yarn copyfiles -u 1 -e \"**/test-*/**/*\" \"contracts/**/*\" ./", "prepublishOnly": "yarn copyfiles -u 1 -e \"**/test-*/**/*\" \"contracts/**/*\" ./",
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment