Skip to content

Commit 28037d5

Browse files
0xVolosnikovfrangio
authored andcommitted
Use leading underscore solhint rule for private constants (#4542)
Co-authored-by: Francisco Giordano <[email protected]>
1 parent d6426d1 commit 28037d5

File tree

12 files changed

+37
-39
lines changed

12 files changed

+37
-39
lines changed

contracts/governance/Governor.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
4343
uint48 eta;
4444
}
4545

46-
bytes32 private constant _ALL_PROPOSAL_STATES_BITMAP = bytes32((2 ** (uint8(type(ProposalState).max) + 1)) - 1);
46+
bytes32 private constant ALL_PROPOSAL_STATES_BITMAP = bytes32((2 ** (uint8(type(ProposalState).max) + 1)) - 1);
4747
string private _name;
4848

4949
mapping(uint256 proposalId => ProposalCore) private _proposals;
@@ -479,7 +479,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
479479

480480
_validateStateBitmap(
481481
proposalId,
482-
_ALL_PROPOSAL_STATES_BITMAP ^
482+
ALL_PROPOSAL_STATES_BITMAP ^
483483
_encodeStateBitmap(ProposalState.Canceled) ^
484484
_encodeStateBitmap(ProposalState.Expired) ^
485485
_encodeStateBitmap(ProposalState.Executed)

contracts/governance/utils/Votes.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {ECDSA} from "../../utils/cryptography/ECDSA.sol";
3131
abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
3232
using Checkpoints for Checkpoints.Trace224;
3333

34-
bytes32 private constant _DELEGATION_TYPEHASH =
34+
bytes32 private constant DELEGATION_TYPEHASH =
3535
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
3636

3737
mapping(address account => address) private _delegatee;
@@ -150,7 +150,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
150150
revert VotesExpiredSignature(expiry);
151151
}
152152
address signer = ECDSA.recover(
153-
_hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
153+
_hashTypedDataV4(keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
154154
v,
155155
r,
156156
s

contracts/proxy/utils/Initializable.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ abstract contract Initializable {
7474
}
7575

7676
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1))
77-
bytes32 private constant _INITIALIZABLE_STORAGE =
78-
0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0e;
77+
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0e;
7978

8079
/**
8180
* @dev The contract is already initialized.
@@ -212,7 +211,7 @@ abstract contract Initializable {
212211
// solhint-disable-next-line var-name-mixedcase
213212
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
214213
assembly {
215-
$.slot := _INITIALIZABLE_STORAGE
214+
$.slot := INITIALIZABLE_STORAGE
216215
}
217216
}
218217
}

contracts/security/ReentrancyGuard.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ abstract contract ReentrancyGuard {
3131
// amount. Since refunds are capped to a percentage of the total
3232
// transaction's gas, it is best to keep them low in cases like this one, to
3333
// increase the likelihood of the full refund coming into effect.
34-
uint256 private constant _NOT_ENTERED = 1;
35-
uint256 private constant _ENTERED = 2;
34+
uint256 private constant NOT_ENTERED = 1;
35+
uint256 private constant ENTERED = 2;
3636

3737
uint256 private _status;
3838

@@ -42,7 +42,7 @@ abstract contract ReentrancyGuard {
4242
error ReentrancyGuardReentrantCall();
4343

4444
constructor() {
45-
_status = _NOT_ENTERED;
45+
_status = NOT_ENTERED;
4646
}
4747

4848
/**
@@ -59,26 +59,26 @@ abstract contract ReentrancyGuard {
5959
}
6060

6161
function _nonReentrantBefore() private {
62-
// On the first call to nonReentrant, _status will be _NOT_ENTERED
63-
if (_status == _ENTERED) {
62+
// On the first call to nonReentrant, _status will be NOT_ENTERED
63+
if (_status == ENTERED) {
6464
revert ReentrancyGuardReentrantCall();
6565
}
6666

6767
// Any calls to nonReentrant after this point will fail
68-
_status = _ENTERED;
68+
_status = ENTERED;
6969
}
7070

7171
function _nonReentrantAfter() private {
7272
// By storing the original value once again, a refund is triggered (see
7373
// https://eips.ethereum.org/EIPS/eip-2200)
74-
_status = _NOT_ENTERED;
74+
_status = NOT_ENTERED;
7575
}
7676

7777
/**
7878
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
7979
* `nonReentrant` function in the call stack.
8080
*/
8181
function _reentrancyGuardEntered() internal view returns (bool) {
82-
return _status == _ENTERED;
82+
return _status == ENTERED;
8383
}
8484
}

contracts/token/ERC20/extensions/ERC20FlashMint.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {ERC20} from "../ERC20.sol";
1919
* overriding {maxFlashLoan} so that it correctly reflects the supply cap.
2020
*/
2121
abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
22-
bytes32 private constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
22+
bytes32 private constant RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
2323

2424
/**
2525
* @dev The loan token is not valid.
@@ -118,7 +118,7 @@ abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
118118
}
119119
uint256 fee = flashFee(token, value);
120120
_mint(address(receiver), value);
121-
if (receiver.onFlashLoan(_msgSender(), token, value, fee, data) != _RETURN_VALUE) {
121+
if (receiver.onFlashLoan(_msgSender(), token, value, fee, data) != RETURN_VALUE) {
122122
revert ERC3156InvalidReceiver(address(receiver));
123123
}
124124
address flashFeeReceiver = _flashFeeReceiver();

contracts/token/ERC20/extensions/ERC20Permit.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {Nonces} from "../../../utils/Nonces.sol";
1818
* need to send a transaction, and thus is not required to hold Ether at all.
1919
*/
2020
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
21-
// solhint-disable-next-line var-name-mixedcase
22-
bytes32 private constant _PERMIT_TYPEHASH =
21+
bytes32 private constant PERMIT_TYPEHASH =
2322
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
2423

2524
/**
@@ -55,7 +54,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
5554
revert ERC2612ExpiredSignature(deadline);
5655
}
5756

58-
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
57+
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
5958

6059
bytes32 hash = _hashTypedDataV4(structHash);
6160

contracts/utils/ShortStrings.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ShortString is bytes32;
3939
*/
4040
library ShortStrings {
4141
// Used as an identifier for strings longer than 31 bytes.
42-
bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
42+
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
4343

4444
error StringTooLong(string str);
4545
error InvalidShortString();
@@ -91,15 +91,15 @@ library ShortStrings {
9191
return toShortString(value);
9292
} else {
9393
StorageSlot.getStringSlot(store).value = value;
94-
return ShortString.wrap(_FALLBACK_SENTINEL);
94+
return ShortString.wrap(FALLBACK_SENTINEL);
9595
}
9696
}
9797

9898
/**
9999
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
100100
*/
101101
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
102-
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
102+
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
103103
return toString(value);
104104
} else {
105105
return store;
@@ -113,7 +113,7 @@ library ShortStrings {
113113
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
114114
*/
115115
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
116-
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
116+
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
117117
return byteLength(value);
118118
} else {
119119
return bytes(store).length;

contracts/utils/Strings.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {SignedMath} from "./math/SignedMath.sol";
1010
* @dev String operations.
1111
*/
1212
library Strings {
13-
bytes16 private constant _HEX_DIGITS = "0123456789abcdef";
14-
uint8 private constant _ADDRESS_LENGTH = 20;
13+
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
14+
uint8 private constant ADDRESS_LENGTH = 20;
1515

1616
/**
1717
* @dev The `value` string doesn't fit in the specified `length`.
@@ -34,7 +34,7 @@ library Strings {
3434
ptr--;
3535
/// @solidity memory-safe-assembly
3636
assembly {
37-
mstore8(ptr, byte(mod(value, 10), _HEX_DIGITS))
37+
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
3838
}
3939
value /= 10;
4040
if (value == 0) break;
@@ -68,7 +68,7 @@ library Strings {
6868
buffer[0] = "0";
6969
buffer[1] = "x";
7070
for (uint256 i = 2 * length + 1; i > 1; --i) {
71-
buffer[i] = _HEX_DIGITS[localValue & 0xf];
71+
buffer[i] = HEX_DIGITS[localValue & 0xf];
7272
localValue >>= 4;
7373
}
7474
if (localValue != 0) {
@@ -81,7 +81,7 @@ library Strings {
8181
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
8282
*/
8383
function toHexString(address addr) internal pure returns (string memory) {
84-
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
84+
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
8585
}
8686

8787
/**

contracts/utils/cryptography/EIP712.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {IERC5267} from "../../interfaces/IERC5267.sol";
3434
abstract contract EIP712 is IERC5267 {
3535
using ShortStrings for *;
3636

37-
bytes32 private constant _TYPE_HASH =
37+
bytes32 private constant TYPE_HASH =
3838
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
3939

4040
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
@@ -86,7 +86,7 @@ abstract contract EIP712 is IERC5267 {
8686
}
8787

8888
function _buildDomainSeparator() private view returns (bytes32) {
89-
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
89+
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
9090
}
9191

9292
/**

contracts/utils/introspection/ERC165Checker.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {IERC165} from "./IERC165.sol";
1414
*/
1515
library ERC165Checker {
1616
// As per the EIP-165 spec, no interface should ever match 0xffffffff
17-
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
17+
bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;
1818

1919
/**
2020
* @dev Returns true if `account` supports the {IERC165} interface.
@@ -24,7 +24,7 @@ library ERC165Checker {
2424
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
2525
return
2626
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
27-
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
27+
!supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);
2828
}
2929

3030
/**

scripts/solhint-custom/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ module.exports = [
4848

4949
VariableDeclaration(node) {
5050
if (node.isDeclaredConst) {
51-
if (/^_/.test(node.name)) {
52-
// TODO: re-enable and fix
53-
// this.error(node, 'Constant variables should not have leading underscore');
51+
// TODO: expand visibility and fix
52+
if (node.visibility === 'private' && /^_/.test(node.name)) {
53+
this.error(node, 'Constant variables should not have leading underscore');
5454
}
5555
} else if (node.visibility === 'private' && !/^_/.test(node.name)) {
5656
this.error(node, 'Non-constant private variables must have leading underscore');

scripts/upgradeable/upgradeable.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ index 3800804a..90c1db78 100644
151151
abstract contract EIP712 is IERC5267 {
152152
- using ShortStrings for *;
153153
-
154-
bytes32 private constant _TYPE_HASH =
154+
bytes32 private constant TYPE_HASH =
155155
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
156156

157157
- // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
@@ -207,8 +207,8 @@ index 3800804a..90c1db78 100644
207207
}
208208

209209
function _buildDomainSeparator() private view returns (bytes32) {
210-
- return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
211-
+ return keccak256(abi.encode(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));
210+
- return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
211+
+ return keccak256(abi.encode(TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));
212212
}
213213

214214
/**

0 commit comments

Comments
 (0)