Skip to content

Commit f5fed71

Browse files
forshtatdrortirosh
andauthored
AA-30: Add eslint task to the repository (eth-infinitism#97)
Co-authored-by: Dror Tirosh <dror@opengsn.org>
1 parent e2333db commit f5fed71

39 files changed

Lines changed: 4801 additions & 3878 deletions

.eslintrc.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
jest: true,
6+
mocha: true,
7+
node: true
8+
},
9+
globals: {
10+
artifacts: false,
11+
assert: false,
12+
contract: false,
13+
web3: false
14+
},
15+
extends:
16+
[
17+
'standard-with-typescript'
18+
],
19+
// This is needed to add configuration to rules with type information
20+
parser: '@typescript-eslint/parser',
21+
parserOptions: {
22+
project: ['./tsconfig.json']
23+
},
24+
ignorePatterns: [
25+
'.eslintrc.js',
26+
'**/types/truffle-contracts',
27+
'dist/'
28+
],
29+
rules: {
30+
'no-console': 'off',
31+
'@typescript-eslint/no-var-requires': 'off',
32+
'@typescript-eslint/return-await': 'off',
33+
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
34+
'@typescript-eslint/require-array-sort-compare': ['error',
35+
{
36+
ignoreStringArrays: true
37+
}
38+
]
39+
},
40+
overrides: [
41+
{
42+
files: '*',
43+
rules: {
44+
'@typescript-eslint/naming-convention': 'off',
45+
'@typescript-eslint/no-non-null-assertion': 'off',
46+
'@typescript-eslint/restrict-template-expressions': 'off'
47+
}
48+
},
49+
{
50+
files: [
51+
'**/test/**/*.ts'
52+
],
53+
rules: {
54+
'no-unused-expressions': 'off',
55+
// chai assertions trigger this rule
56+
'@typescript-eslint/no-unused-expressions': 'off',
57+
'@typescript-eslint/no-non-null-assertion': 'off'
58+
}
59+
},
60+
{
61+
// otherwise it will raise an error in every JavaScript file
62+
files: ['*.ts'],
63+
rules: {
64+
'@typescript-eslint/prefer-ts-expect-error': 'off',
65+
// allow using '${val}' with numbers, bool and null types
66+
'@typescript-eslint/restrict-template-expressions': [
67+
'error',
68+
{
69+
allowNumber: true,
70+
allowBoolean: true,
71+
allowNullish: true,
72+
allowNullable: true
73+
}
74+
]
75+
}
76+
}
77+
]
78+
}

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ jobs:
2929

3030
- run: yarn run ci
3131

32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/setup-node@v1
36+
with:
37+
node-version: '14'
38+
- uses: actions/checkout@v1
39+
- uses: actions/cache@v2
40+
with:
41+
path: node_modules
42+
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
43+
- run: yarn install
44+
- run: yarn lint
45+
3246
coverage:
3347
runs-on: ubuntu-latest
3448
steps:

.solhint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "solhint:recommended",
3+
"rules": {
4+
"compiler-version": ["error",">=0.7.5"],
5+
"func-visibility": ["off",{"ignoreConstructors":true}],
6+
"mark-callable-contracts": ["off"]
7+
}
8+
}

contracts/BasePaymaster.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.12;
3+
4+
5+
/* solhint-disable reason-string */
6+
37
import "@openzeppelin/contracts/access/Ownable.sol";
48
import "./IPaymaster.sol";
59
import "./EntryPoint.sol";

contracts/BaseWallet.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.12;
33

4+
/* solhint-disable avoid-low-level-calls */
5+
/* solhint-disable no-inline-assembly */
6+
/* solhint-disable reason-string */
7+
48
import "./IWallet.sol";
59
import "./EntryPoint.sol";
610

contracts/EntryPoint.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// SPDX-License-Identifier: GPL-3.0
66
pragma solidity ^0.8.12;
77

8+
/* solhint-disable avoid-low-level-calls */
9+
/* solhint-disable no-inline-assembly */
10+
/* solhint-disable reason-string */
11+
812
import "./StakeManager.sol";
913
import "./UserOperation.sol";
1014
import "./IWallet.sol";
@@ -251,6 +255,7 @@ contract EntryPoint is StakeManager {
251255
uint256 bal = balanceOf(sender);
252256
missingWalletFunds = bal > requiredPrefund ? 0 : requiredPrefund - bal;
253257
}
258+
// solhint-disable-next-line no-empty-blocks
254259
try IWallet(sender).validateUserOp{gas : op.verificationGas}(op, requestId, missingWalletFunds) {
255260
} catch Error(string memory revertReason) {
256261
revert FailedOp(opIndex, address(0), revertReason);
@@ -363,6 +368,7 @@ contract EntryPoint is StakeManager {
363368
if (mode != IPaymaster.PostOpMode.postOpReverted) {
364369
IPaymaster(paymaster).postOp{gas : op.verificationGas}(mode, context, actualGasCost);
365370
} else {
371+
// solhint-disable-next-line no-empty-blocks
366372
try IPaymaster(paymaster).postOp{gas : op.verificationGas}(mode, context, actualGasCost) {}
367373
catch Error(string memory reason) {
368374
revert FailedOp(opIndex, paymaster, reason);

contracts/StakeManager.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
pragma solidity ^0.8.12;
33

4+
/* solhint-disable avoid-low-level-calls */
5+
/* solhint-disable not-rely-on-time */
46
/**
57
* manage deposits and stakes.
68
* deposit is just a balance used to pay for UserOperations (either by a paymaster or a wallet)
@@ -92,7 +94,7 @@ abstract contract StakeManager {
9294
function internalIncrementDeposit(address account, uint256 amount) internal {
9395
DepositInfo storage info = deposits[account];
9496
uint256 newAmount = info.deposit + amount;
95-
require(newAmount <= type(uint112).max, 'deposit overflow');
97+
require(newAmount <= type(uint112).max, "deposit overflow");
9698
info.deposit = uint112(newAmount);
9799
}
98100

contracts/UserOperation.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.12;
33

4+
/* solhint-disable no-inline-assembly */
5+
46
/**
57
* User Operation struct
68
* @param sender the sender account of this request

contracts/samples/DepositPaymaster.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.12;
33

4+
/* solhint-disable reason-string */
5+
46
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
57
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
68

@@ -28,9 +30,9 @@ contract DepositPaymaster is BasePaymaster {
2830
using SafeERC20 for IERC20;
2931

3032
//calculated cost of the postOp
31-
uint256 constant COST_OF_POST = 35000;
33+
uint256 constant public COST_OF_POST = 35000;
3234

33-
IOracle private constant nullOracle = IOracle(address(0));
35+
IOracle private constant NULL_ORACLE = IOracle(address(0));
3436
mapping(IERC20 => IOracle) public oracles;
3537
mapping(IERC20 => mapping(address => uint256)) public balances;
3638
mapping(address => uint256) public unlockBlock;
@@ -44,7 +46,7 @@ contract DepositPaymaster is BasePaymaster {
4446
* owner of the paymaster should add supported tokens
4547
*/
4648
function addToken(IERC20 token, IOracle tokenPriceOracle) external onlyOwner {
47-
require(oracles[token] == nullOracle);
49+
require(oracles[token] == NULL_ORACLE);
4850
oracles[token] = tokenPriceOracle;
4951
}
5052

@@ -61,7 +63,7 @@ contract DepositPaymaster is BasePaymaster {
6163
function addDepositFor(IERC20 token, address account, uint256 amount) external {
6264
//(sender must have approval for the paymaster)
6365
token.safeTransferFrom(msg.sender, address(this), amount);
64-
require(oracles[token] != nullOracle, "unsupported token");
66+
require(oracles[token] != NULL_ORACLE, "unsupported token");
6567
balances[token][account] += amount;
6668
if (msg.sender == account) {
6769
lockTokenDeposit();
@@ -110,7 +112,7 @@ contract DepositPaymaster is BasePaymaster {
110112
*/
111113
function getTokenValueOfEth(IERC20 token, uint256 ethBought) internal view virtual returns (uint256 requiredTokens) {
112114
IOracle oracle = oracles[token];
113-
require(oracle != nullOracle, "DepositPaymaster: unsupported token");
115+
require(oracle != NULL_ORACLE, "DepositPaymaster: unsupported token");
114116
return oracle.getTokenValueOfEth(ethBought);
115117
}
116118

contracts/samples/SimpleWallet.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.12;
33

4+
/* solhint-disable avoid-low-level-calls */
5+
/* solhint-disable no-inline-assembly */
6+
/* solhint-disable reason-string */
7+
48
import "../BaseWallet.sol";
59
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
610

@@ -30,6 +34,7 @@ contract SimpleWallet is BaseWallet {
3034

3135
event EntryPointChanged(address indexed oldEntryPoint, address indexed newEntryPoint);
3236

37+
// solhint-disable-next-line no-empty-blocks
3338
receive() external payable {}
3439

3540
constructor(EntryPoint anEntryPoint, address anOwner) {

0 commit comments

Comments
 (0)