Skip to content

Commit 97894a1

Browse files
authored
Adhere to naming convention (#2150)
* Upgrade to latest solhint rc * Add private-vars-leading-underscore linter rule * Add leading underscore to GSNRecipient constants * Remove leading underscore from ERC165Checker functions * Add leading underscore to multiple private constants * Fix linter errors in mocks * Add leading underscore to ERC777's ERC1820 registry * Add changelog entry
1 parent 4476a2d commit 97894a1

16 files changed

+2438
-1217
lines changed

.solhint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"func-order": "off",
55
"mark-callable-contracts": "off",
66
"no-empty-blocks": "off",
7-
"compiler-version": ["error", "^0.6.0"]
7+
"compiler-version": ["error", "^0.6.0"],
8+
"private-vars-leading-underscore": "error"
89
}
910
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* `Address`: removed `toPayable`, use `payable(address)` instead. ([#2133](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2133))
2626
* `ERC777`: `_send`, `_mint` and `_burn` now use the caller as the operator. ([#2134](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2134))
2727
* `ERC777`: removed `_callsTokensToSend` and `_callTokensReceived`. ([#2134](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2134))
28+
* `ERC165Checker`: functions no longer have a leading underscore. ([#2150](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2150))
2829

2930
## 2.5.0 (2020-02-04)
3031

contracts/GSN/GSNRecipient.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ abstract contract GSNRecipient is IRelayRecipient, Context {
1919
// Default RelayHub address, deployed on mainnet and all testnets at the same address
2020
address private _relayHub = 0xD216153c06E857cD7f72665E0aF1d7D82172F494;
2121

22-
uint256 constant private RELAYED_CALL_ACCEPTED = 0;
23-
uint256 constant private RELAYED_CALL_REJECTED = 11;
22+
uint256 constant private _RELAYED_CALL_ACCEPTED = 0;
23+
uint256 constant private _RELAYED_CALL_REJECTED = 11;
2424

2525
// How much gas is forwarded to postRelayedCall
26-
uint256 constant internal POST_RELAYED_CALL_MAX_GAS = 100000;
26+
uint256 constant internal _POST_RELAYED_CALL_MAX_GAS = 100000;
2727

2828
/**
2929
* @dev Emitted when a contract changes its {IRelayHub} contract to a new one.
@@ -170,14 +170,14 @@ abstract contract GSNRecipient is IRelayRecipient, Context {
170170
* This overload forwards `context` to _preRelayedCall and _postRelayedCall.
171171
*/
172172
function _approveRelayedCall(bytes memory context) internal pure returns (uint256, bytes memory) {
173-
return (RELAYED_CALL_ACCEPTED, context);
173+
return (_RELAYED_CALL_ACCEPTED, context);
174174
}
175175

176176
/**
177177
* @dev Return this in acceptRelayedCall to impede execution of a relayed call. No fees will be charged.
178178
*/
179179
function _rejectRelayedCall(uint256 errorCode) internal pure returns (uint256, bytes memory) {
180-
return (RELAYED_CALL_REJECTED + errorCode, "");
180+
return (_RELAYED_CALL_REJECTED + errorCode, "");
181181
}
182182

183183
/*

contracts/GSN/GSNRecipientERC20Fee.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
9797
// actualCharge is an _estimated_ charge, which assumes postRelayedCall will use all available gas.
9898
// This implementation's gas cost can be roughly estimated as 10k gas, for the two SSTORE operations in an
9999
// ERC20 transfer.
100-
uint256 overestimation = _computeCharge(POST_RELAYED_CALL_MAX_GAS.sub(10000), gasPrice, transactionFee);
100+
uint256 overestimation = _computeCharge(_POST_RELAYED_CALL_MAX_GAS.sub(10000), gasPrice, transactionFee);
101101
actualCharge = actualCharge.sub(overestimation);
102102

103103
// After the relayed call has been executed and the actual charge estimated, the excess pre-charge is returned
@@ -113,7 +113,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
113113
*/
114114
// solhint-disable-next-line contract-name-camelcase
115115
contract __unstable__ERC20Owned is ERC20, ERC20Detailed, Ownable {
116-
uint256 private constant UINT256_MAX = 2**256 - 1;
116+
uint256 private constant _UINT256_MAX = 2**256 - 1;
117117

118118
constructor(string memory name, string memory symbol, uint8 decimals) public ERC20Detailed(name, symbol, decimals) { }
119119

@@ -125,7 +125,7 @@ contract __unstable__ERC20Owned is ERC20, ERC20Detailed, Ownable {
125125
// The owner has 'infinite' allowance for all token holders
126126
function allowance(address tokenOwner, address spender) public view override(ERC20, IERC20) returns (uint256) {
127127
if (spender == owner()) {
128-
return UINT256_MAX;
128+
return _UINT256_MAX;
129129
} else {
130130
return super.allowance(tokenOwner, spender);
131131
}

contracts/introspection/ERC165Checker.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ library ERC165Checker {
1919
/**
2020
* @dev Returns true if `account` supports the {IERC165} interface,
2121
*/
22-
function _supportsERC165(address account) internal view returns (bool) {
22+
function supportsERC165(address account) internal view returns (bool) {
2323
// Any contract that implements ERC165 must explicitly indicate support of
2424
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
2525
return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) &&
@@ -32,9 +32,9 @@ library ERC165Checker {
3232
*
3333
* See {IERC165-supportsInterface}.
3434
*/
35-
function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
35+
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
3636
// query support of both ERC165 as per the spec and support of _interfaceId
37-
return _supportsERC165(account) &&
37+
return supportsERC165(account) &&
3838
_supportsERC165Interface(account, interfaceId);
3939
}
4040

@@ -47,9 +47,9 @@ library ERC165Checker {
4747
*
4848
* See {IERC165-supportsInterface}.
4949
*/
50-
function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
50+
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
5151
// query support of ERC165 itself
52-
if (!_supportsERC165(account)) {
52+
if (!supportsERC165(account)) {
5353
return false;
5454
}
5555

@@ -72,7 +72,7 @@ library ERC165Checker {
7272
* identifier interfaceId, false otherwise
7373
* @dev Assumes that account contains a contract that supports ERC165, otherwise
7474
* the behavior of this method is undefined. This precondition can be checked
75-
* with the `supportsERC165` method in this library.
75+
* with {supportsERC165}.
7676
* Interface identification is specified in ERC-165.
7777
*/
7878
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {

contracts/introspection/ERC1820Implementer.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import "./IERC1820Implementer.sol";
1111
* registration to be complete.
1212
*/
1313
contract ERC1820Implementer is IERC1820Implementer {
14-
bytes32 constant private ERC1820_ACCEPT_MAGIC = keccak256(abi.encodePacked("ERC1820_ACCEPT_MAGIC"));
14+
bytes32 constant private _ERC1820_ACCEPT_MAGIC = keccak256(abi.encodePacked("ERC1820_ACCEPT_MAGIC"));
1515

1616
mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
1717

1818
/**
1919
* See {IERC1820Implementer-canImplementInterfaceForAddress}.
2020
*/
2121
function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view override returns (bytes32) {
22-
return _supportedInterfaces[interfaceHash][account] ? ERC1820_ACCEPT_MAGIC : bytes32(0x00);
22+
return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
2323
}
2424

2525
/**

contracts/math/SignedSafeMath.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.6.0;
55
* @dev Signed math operations with safety checks that revert on error.
66
*/
77
library SignedSafeMath {
8-
int256 constant private INT256_MIN = -2**255;
8+
int256 constant private _INT256_MIN = -2**255;
99

1010
/**
1111
* @dev Multiplies two signed integers, reverts on overflow.
@@ -18,7 +18,7 @@ library SignedSafeMath {
1818
return 0;
1919
}
2020

21-
require(!(a == -1 && b == INT256_MIN), "SignedSafeMath: multiplication overflow");
21+
require(!(a == -1 && b == _INT256_MIN), "SignedSafeMath: multiplication overflow");
2222

2323
int256 c = a * b;
2424
require(c / a == b, "SignedSafeMath: multiplication overflow");
@@ -31,7 +31,7 @@ library SignedSafeMath {
3131
*/
3232
function div(int256 a, int256 b) internal pure returns (int256) {
3333
require(b != 0, "SignedSafeMath: division by zero");
34-
require(!(b == -1 && a == INT256_MIN), "SignedSafeMath: division overflow");
34+
require(!(b == -1 && a == _INT256_MIN), "SignedSafeMath: division overflow");
3535

3636
int256 c = a / b;
3737

contracts/mocks/ArraysImpl.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import "../utils/Arrays.sol";
55
contract ArraysImpl {
66
using Arrays for uint256[];
77

8-
uint256[] private array;
8+
uint256[] private _array;
99

10-
constructor (uint256[] memory _array) public {
11-
array = _array;
10+
constructor (uint256[] memory array) public {
11+
_array = array;
1212
}
1313

14-
function findUpperBound(uint256 _element) external view returns (uint256) {
15-
return array.findUpperBound(_element);
14+
function findUpperBound(uint256 element) external view returns (uint256) {
15+
return _array.findUpperBound(element);
1616
}
1717
}

contracts/mocks/ERC165CheckerMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ contract ERC165CheckerMock {
66
using ERC165Checker for address;
77

88
function supportsERC165(address account) public view returns (bool) {
9-
return account._supportsERC165();
9+
return account.supportsERC165();
1010
}
1111

1212
function supportsInterface(address account, bytes4 interfaceId) public view returns (bool) {
13-
return account._supportsInterface(interfaceId);
13+
return account.supportsInterface(interfaceId);
1414
}
1515

1616
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) public view returns (bool) {
17-
return account._supportsAllInterfaces(interfaceIds);
17+
return account.supportsAllInterfaces(interfaceIds);
1818
}
1919
}

contracts/mocks/ERC777SenderRecipientMock.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
3737

3838
IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
3939

40-
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
41-
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
40+
bytes32 constant private _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
41+
bytes32 constant private _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
4242

4343
function tokensToSend(
4444
address operator,
@@ -103,7 +103,7 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
103103
}
104104

105105
function senderFor(address account) public {
106-
_registerInterfaceForAddress(TOKENS_SENDER_INTERFACE_HASH, account);
106+
_registerInterfaceForAddress(_TOKENS_SENDER_INTERFACE_HASH, account);
107107

108108
address self = address(this);
109109
if (account == self) {
@@ -112,11 +112,11 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
112112
}
113113

114114
function registerSender(address sender) public {
115-
_erc1820.setInterfaceImplementer(address(this), TOKENS_SENDER_INTERFACE_HASH, sender);
115+
_erc1820.setInterfaceImplementer(address(this), _TOKENS_SENDER_INTERFACE_HASH, sender);
116116
}
117117

118118
function recipientFor(address account) public {
119-
_registerInterfaceForAddress(TOKENS_RECIPIENT_INTERFACE_HASH, account);
119+
_registerInterfaceForAddress(_TOKENS_RECIPIENT_INTERFACE_HASH, account);
120120

121121
address self = address(this);
122122
if (account == self) {
@@ -125,7 +125,7 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
125125
}
126126

127127
function registerRecipient(address recipient) public {
128-
_erc1820.setInterfaceImplementer(address(this), TOKENS_RECIPIENT_INTERFACE_HASH, recipient);
128+
_erc1820.setInterfaceImplementer(address(this), _TOKENS_RECIPIENT_INTERFACE_HASH, recipient);
129129
}
130130

131131
function setShouldRevertSend(bool shouldRevert) public {

contracts/mocks/EnumerableSetMock.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ contract EnumerableSetMock{
77

88
event TransactionResult(bool result);
99

10-
EnumerableSet.AddressSet private set;
10+
EnumerableSet.AddressSet private _set;
1111

1212
function contains(address value) public view returns (bool) {
13-
return set.contains(value);
13+
return _set.contains(value);
1414
}
1515

1616
function add(address value) public {
17-
bool result = set.add(value);
17+
bool result = _set.add(value);
1818
emit TransactionResult(result);
1919
}
2020

2121
function remove(address value) public {
22-
bool result = set.remove(value);
22+
bool result = _set.remove(value);
2323
emit TransactionResult(result);
2424
}
2525

2626
function enumerate() public view returns (address[] memory) {
27-
return set.enumerate();
27+
return _set.enumerate();
2828
}
2929

3030
function length() public view returns (uint256) {
31-
return set.length();
31+
return _set.length();
3232
}
3333

3434
function get(uint256 index) public view returns (address) {
35-
return set.get(index);
35+
return _set.get(index);
3636
}
3737
}

contracts/mocks/ReentrancyMock.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ contract ReentrancyMock is ReentrancyGuard {
1111
}
1212

1313
function callback() external nonReentrant {
14-
count();
14+
_count();
1515
}
1616

1717
function countLocalRecursive(uint256 n) public nonReentrant {
1818
if (n > 0) {
19-
count();
19+
_count();
2020
countLocalRecursive(n - 1);
2121
}
2222
}
2323

2424
function countThisRecursive(uint256 n) public nonReentrant {
2525
if (n > 0) {
26-
count();
26+
_count();
2727
// solhint-disable-next-line avoid-low-level-calls
2828
(bool success,) = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
2929
require(success, "ReentrancyMock: failed call");
3030
}
3131
}
3232

3333
function countAndCall(ReentrancyAttack attacker) public nonReentrant {
34-
count();
34+
_count();
3535
bytes4 func = bytes4(keccak256("callback()"));
3636
attacker.callSender(func);
3737
}
3838

39-
function count() private {
39+
function _count() private {
4040
counter += 1;
4141
}
4242
}

contracts/token/ERC20/SafeERC20.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ library SafeERC20 {
1818
using Address for address;
1919

2020
function safeTransfer(IERC20 token, address to, uint256 value) internal {
21-
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
21+
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
2222
}
2323

2424
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
25-
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
25+
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
2626
}
2727

2828
function safeApprove(IERC20 token, address spender, uint256 value) internal {
@@ -33,17 +33,17 @@ library SafeERC20 {
3333
require((value == 0) || (token.allowance(address(this), spender) == 0),
3434
"SafeERC20: approve from non-zero to non-zero allowance"
3535
);
36-
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
36+
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
3737
}
3838

3939
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
4040
uint256 newAllowance = token.allowance(address(this), spender).add(value);
41-
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
41+
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
4242
}
4343

4444
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
4545
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
46-
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
46+
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
4747
}
4848

4949
/**
@@ -52,7 +52,7 @@ library SafeERC20 {
5252
* @param token The token targeted by the call.
5353
* @param data The call data (encoded using abi.encode or one of its variants).
5454
*/
55-
function callOptionalReturn(IERC20 token, bytes memory data) private {
55+
function _callOptionalReturn(IERC20 token, bytes memory data) private {
5656
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
5757
// we're implementing it ourselves.
5858

0 commit comments

Comments
 (0)