Use leading underscore solhint rule for private constants (#4542)

Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
Vladislav Volosnikov
2023-08-29 23:25:35 +02:00
committed by GitHub
parent a5ed318634
commit 812404cee8
12 changed files with 37 additions and 39 deletions

View File

@ -39,7 +39,7 @@ type ShortString is bytes32;
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
@ -91,7 +91,7 @@ library ShortStrings {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(_FALLBACK_SENTINEL);
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
@ -99,7 +99,7 @@ library ShortStrings {
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
@ -113,7 +113,7 @@ library ShortStrings {
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;

View File

@ -10,8 +10,8 @@ import {SignedMath} from "./math/SignedMath.sol";
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_DIGITS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
@ -34,7 +34,7 @@ library Strings {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _HEX_DIGITS))
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
@ -68,7 +68,7 @@ library Strings {
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_DIGITS[localValue & 0xf];
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
@ -81,7 +81,7 @@ library Strings {
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**

View File

@ -34,7 +34,7 @@ import {IERC5267} from "../../interfaces/IERC5267.sol";
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant _TYPE_HASH =
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// 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 {
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**

View File

@ -14,7 +14,7 @@ import {IERC165} from "./IERC165.sol";
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;
/**
* @dev Returns true if `account` supports the {IERC165} interface.
@ -24,7 +24,7 @@ library ERC165Checker {
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
!supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);
}
/**