Skip to content

Commit 98be452

Browse files
authored
ci: move from prettier to forge fmt (#160)
* add fmt configurations * apply forge fmt * change husky pre-commit * change git ci yarn lint to forge fmt * yarn remove prettier, solhint, prettier-plugin-solidity, solhint-plugin-prettier * enable forge fmt only on staged changes
1 parent 792fcb6 commit 98be452

16 files changed

+145
-1431
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ jobs:
3838
- name: Install dependencies
3939
run: yarn install
4040

41-
- name: Run linter
42-
run: yarn lint
43-
4441
- name: Run audit
4542
run: yarn audit
4643

@@ -54,6 +51,9 @@ jobs:
5451
forge --version
5552
forge build --sizes
5653
54+
- name: Run forge formatter
55+
run: forge fmt
56+
5757
- name: Run forge tests
5858
run: forge test -vvv
5959

.husky/pre-commit

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
3-
4-
yarn lint-staged
5-
forge snapshot --check --match-contract Gas
3+
forge snapshot --check --match-contract Gas
4+
npx lint-staged

.lintstagedrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"*.{json,md,sol,yml}": [
3-
"prettier --config ./.prettierrc.yml --write"
2+
"*.sol": [
3+
"forge fmt --check"
44
]
55
}

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ verbosity = 3
77

88
[fuzz]
99
runs = 512
10+
11+
[fmt]
12+
line_length = 120
13+
tab_width = 4
14+
quote_style = "double"
15+
bracket_spacing = false
16+
int_types = "long"
17+
multiline_func_header = "params_first"

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
"license": "None",
1010
"devDependencies": {
1111
"husky": "^8.0.1",
12-
"lint-staged": "^13.0.2",
13-
"prettier": "^2.7.1",
14-
"prettier-plugin-solidity": "^1.0.0-beta.19",
15-
"solhint": "^3.3.7",
16-
"solhint-plugin-prettier": "^0.0.5"
12+
"lint-staged": "^13.0.2"
1713
},
1814
"scripts": {
1915
"lint": "yarn solhint && yarn prettier:check",

src/BundleRegistry.sol

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ contract BundleRegistry is Ownable {
6767
* @param _nameRegistry The address of the NameRegistry UUPS Proxy contract
6868
* @param _trustedCaller The address that can call trustedRegister and partialTrustedRegister
6969
*/
70-
constructor(
71-
address _idRegistry,
72-
address _nameRegistry,
73-
address _trustedCaller
74-
) Ownable() {
70+
constructor(address _idRegistry, address _nameRegistry, address _trustedCaller) Ownable() {
7571
idRegistry = IdRegistry(_idRegistry);
7672
nameRegistry = NameRegistry(_nameRegistry);
7773
trustedCaller = _trustedCaller;
@@ -96,7 +92,7 @@ contract BundleRegistry is Ownable {
9692
// Return any funds returned by the NameRegistry back to the caller
9793
if (address(this).balance > 0) {
9894
// solhint-disable-next-line avoid-low-level-calls
99-
(bool success, ) = msg.sender.call{value: address(this).balance}("");
95+
(bool success,) = msg.sender.call{value: address(this).balance}("");
10096
if (!success) revert CallFailed();
10197
}
10298
}

src/IdRegistry.sol

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ contract IdRegistry is ERC2771Context, Ownable {
190190
* @param recovery The address which can recover the fid
191191
* @param url The home url for the fid's off-chain data
192192
*/
193-
function register(
194-
address to,
195-
address recovery,
196-
string calldata url
197-
) external {
193+
function register(address to, address recovery, string calldata url) external {
198194
// Perf: Don't check to == address(0) to save 29 gas since 0x0 can only register 1 fid
199195

200196
if (trustedOnly == 1) revert Invitable();
@@ -213,11 +209,7 @@ contract IdRegistry is ERC2771Context, Ownable {
213209
* @param recovery The address which can recover the fid
214210
* @param url The home url for the fid's off-chain data
215211
*/
216-
function trustedRegister(
217-
address to,
218-
address recovery,
219-
string calldata url
220-
) external {
212+
function trustedRegister(address to, address recovery, string calldata url) external {
221213
// Perf: Don't check to == address(0) to save 29 gas since 0x0 can only register 1 fid
222214

223215
if (trustedOnly == 0) revert Registrable();
@@ -287,11 +279,7 @@ contract IdRegistry is ERC2771Context, Ownable {
287279
* @dev Transfer the fid to another address, clear the recovery address and reset active
288280
* recovery requests, without checking any invariants.
289281
*/
290-
function _unsafeTransfer(
291-
uint256 id,
292-
address from,
293-
address to
294-
) internal {
282+
function _unsafeTransfer(uint256 id, address from, address to) internal {
295283
idOf[to] = id;
296284
delete idOf[from];
297285

@@ -321,7 +309,8 @@ contract IdRegistry is ERC2771Context, Ownable {
321309
* changeRecoveryAddress(), which requires idOf[addr] != 0
322310
* 4. idOf[addr] becomes 0 only in transfer() and completeRecovery(), which requires
323311
* recoveryOf[addr] == address(0)
324-
**/
312+
*
313+
*/
325314

326315
/**
327316
* INVARIANT 2: If an address has a non-zero recoveryClock, it must also have an fid
@@ -459,9 +448,7 @@ contract IdRegistry is ERC2771Context, Ownable {
459448
/**
460449
* @notice Override to prevent a single-step transfer of ownership
461450
*/
462-
function transferOwnership(
463-
address /*newOwner*/
464-
) public view override onlyOwner {
451+
function transferOwnership(address /*newOwner*/ ) public view override onlyOwner {
465452
revert Unauthorized();
466453
}
467454

@@ -491,11 +478,11 @@ contract IdRegistry is ERC2771Context, Ownable {
491478
OPEN ZEPPELIN OVERRIDES
492479
//////////////////////////////////////////////////////////////*/
493480

494-
function _msgSender() internal view override(Context, ERC2771Context) returns (address) {
481+
function _msgSender() internal view override (Context, ERC2771Context) returns (address) {
495482
return ERC2771Context._msgSender();
496483
}
497484

498-
function _msgData() internal view override(Context, ERC2771Context) returns (bytes calldata) {
485+
function _msgData() internal view override (Context, ERC2771Context) returns (bytes calldata) {
499486
return ERC2771Context._msgData();
500487
}
501488
}

src/NameRegistry.sol

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,7 @@ contract NameRegistry is
414414
* @param secret The secret value in the commitment
415415
* @param recovery The address which can recovery the fname if the custody address is lost
416416
*/
417-
function register(
418-
bytes16 fname,
419-
address to,
420-
bytes32 secret,
421-
address recovery
422-
) external payable {
417+
function register(bytes16 fname, address to, bytes32 secret, address recovery) external payable {
423418
bytes32 commit = generateCommit(fname, to, secret, recovery);
424419

425420
uint256 _fee = fee;
@@ -463,7 +458,7 @@ contract NameRegistry is
463458
if (overpayment > 0) {
464459
// Perf: Call msg.sender instead of _msgSender() to save ~100 gas b/c we don't need meta-tx
465460
// solhint-disable-next-line avoid-low-level-calls
466-
(bool success, ) = msg.sender.call{value: overpayment}("");
461+
(bool success,) = msg.sender.call{value: overpayment}("");
467462
if (!success) revert CallFailed();
468463
}
469464
}
@@ -548,7 +543,7 @@ contract NameRegistry is
548543
if (overpayment > 0) {
549544
// Perf: Call msg.sender instead of _msgSender() to save ~100 gas b/c we don't need meta-tx
550545
// solhint-disable-next-line avoid-low-level-calls
551-
(bool success, ) = msg.sender.call{value: overpayment}("");
546+
(bool success,) = msg.sender.call{value: overpayment}("");
552547
if (!success) revert CallFailed();
553548
}
554549
}
@@ -562,11 +557,7 @@ contract NameRegistry is
562557
* @param tokenId The uint256 representation of the fname to bid on
563558
* @param recovery The address which can recovery the fname if the custody address is lost
564559
*/
565-
function bid(
566-
address to,
567-
uint256 tokenId,
568-
address recovery
569-
) external payable {
560+
function bid(address to, uint256 tokenId, address recovery) external payable {
570561
// Check that the tokenID was previously registered
571562
uint256 expiryTs = expiryOf[tokenId];
572563
if (expiryTs == 0) revert Registrable();
@@ -627,11 +618,9 @@ contract NameRegistry is
627618

628619
// Safety/Audit: the below cannot intuitively underflow or overflow given the ranges,
629620
// but needs proof
630-
price =
631-
BID_START_PRICE.mulWadDown(
632-
uint256(FixedPointMathLib.powWad(int256(BID_PERIOD_DECREASE_UD60X18), periodsSD59x18))
633-
) +
634-
fee;
621+
price = BID_START_PRICE.mulWadDown(
622+
uint256(FixedPointMathLib.powWad(int256(BID_PERIOD_DECREASE_UD60X18), periodsSD59x18))
623+
) + fee;
635624
}
636625

637626
if (msg.value < price) revert InsufficientFunds();
@@ -656,7 +645,7 @@ contract NameRegistry is
656645
if (overpayment > 0) {
657646
// Perf: Call msg.sender instead of _msgSender() to save ~100 gas b/c we don't need meta-tx
658647
// solhint-disable-next-line avoid-low-level-calls
659-
(bool success, ) = msg.sender.call{value: overpayment}("");
648+
(bool success,) = msg.sender.call{value: overpayment}("");
660649
if (!success) revert CallFailed();
661650
}
662651
}
@@ -690,11 +679,7 @@ contract NameRegistry is
690679
* @param to The address to transfer the fname to
691680
* @param tokenId The uint256 representation of the fname to transfer
692681
*/
693-
function transferFrom(
694-
address from,
695-
address to,
696-
uint256 tokenId
697-
) public override {
682+
function transferFrom(address from, address to, uint256 tokenId) public override {
698683
uint256 expiryTs = expiryOf[tokenId];
699684

700685
// Expired names should not be transferrable by the previous owner
@@ -711,12 +696,7 @@ contract NameRegistry is
711696
* @param tokenId The uint256 representation of the fname to transfer
712697
* @param data Additional data with no specified format, sent in call to `to`
713698
*/
714-
function safeTransferFrom(
715-
address from,
716-
address to,
717-
uint256 tokenId,
718-
bytes memory data
719-
) public override {
699+
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override {
720700
uint256 expiryTs = expiryOf[tokenId];
721701

722702
// Expired names should not be transferrable by the previous owner
@@ -740,7 +720,7 @@ contract NameRegistry is
740720
_validateName(fname);
741721

742722
// Step back from the last byte to find the first non-zero byte
743-
for (uint256 i = 15; ; ) {
723+
for (uint256 i = 15;;) {
744724
if (uint8(fname[i]) != 0) {
745725
lastCharIdx = i;
746726
break;
@@ -758,7 +738,7 @@ contract NameRegistry is
758738
// Construct a new bytes[] with the valid fname characters.
759739
bytes memory fnameBytes = new bytes(lastCharIdx + 1);
760740

761-
for (uint256 j = 0; j <= lastCharIdx; ) {
741+
for (uint256 j = 0; j <= lastCharIdx;) {
762742
fnameBytes[j] = fname[j];
763743

764744
unchecked {
@@ -773,22 +753,14 @@ contract NameRegistry is
773753
/**
774754
* @dev Hook that ensures that token transfers cannot occur when the contract is paused.
775755
*/
776-
function _beforeTokenTransfer(
777-
address from,
778-
address to,
779-
uint256 tokenId
780-
) internal override whenNotPaused {
756+
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override whenNotPaused {
781757
super._beforeTokenTransfer(from, to, tokenId);
782758
}
783759

784760
/**
785761
* @dev Hook that ensures that recovery address is reset whenever a transfer occurs.
786762
*/
787-
function _afterTokenTransfer(
788-
address from,
789-
address to,
790-
uint256 tokenId
791-
) internal override {
763+
function _afterTokenTransfer(address from, address to, uint256 tokenId) internal override {
792764
super._afterTokenTransfer(from, to, tokenId);
793765

794766
// Checking state before clearing is more gas-efficient than always clearing
@@ -1018,7 +990,7 @@ contract NameRegistry is
1018990
if (address(this).balance < amount) revert InsufficientFunds();
1019991

1020992
// solhint-disable-next-line avoid-low-level-calls
1021-
(bool success, ) = vault.call{value: amount}("");
993+
(bool success,) = vault.call{value: amount}("");
1022994
if (!success) revert CallFailed();
1023995
}
1024996

@@ -1051,20 +1023,25 @@ contract NameRegistry is
10511023
function _msgSender()
10521024
internal
10531025
view
1054-
override(ContextUpgradeable, ERC2771ContextUpgradeable)
1026+
override (ContextUpgradeable, ERC2771ContextUpgradeable)
10551027
returns (address sender)
10561028
{
10571029
sender = ERC2771ContextUpgradeable._msgSender();
10581030
}
10591031

1060-
function _msgData() internal view override(ContextUpgradeable, ERC2771ContextUpgradeable) returns (bytes calldata) {
1032+
function _msgData()
1033+
internal
1034+
view
1035+
override (ContextUpgradeable, ERC2771ContextUpgradeable)
1036+
returns (bytes calldata)
1037+
{
10611038
return ERC2771ContextUpgradeable._msgData();
10621039
}
10631040

10641041
function supportsInterface(bytes4 interfaceId)
10651042
public
10661043
view
1067-
override(AccessControlUpgradeable, ERC721Upgradeable)
1044+
override (AccessControlUpgradeable, ERC721Upgradeable)
10681045
returns (bool)
10691046
{
10701047
return ERC721Upgradeable.supportsInterface(interfaceId);
@@ -1097,7 +1074,7 @@ contract NameRegistry is
10971074
// If the name begins with a hyphen, reject it
10981075
if (uint8(fname[0]) == 45) revert InvalidName();
10991076

1100-
for (uint256 i = 0; i < length; ) {
1077+
for (uint256 i = 0; i < length;) {
11011078
uint8 charInt = uint8(fname[i]);
11021079

11031080
unchecked {

test/BundleRegistry.t.sol

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ contract BundleRegistryTest is Test {
234234
PARTIAL TRUSTED REGISTER TESTS
235235
//////////////////////////////////////////////////////////////*/
236236

237-
function testPartialTrustedRegister(
238-
address alice,
239-
address recovery,
240-
string calldata url,
241-
uint256 inviter
242-
) public {
237+
function testPartialTrustedRegister(address alice, address recovery, string calldata url, uint256 inviter) public {
243238
vm.assume(alice != address(0)); // OZ's ERC-721 throws when a zero-address mints an NFT
244239

245240
// State: Trusted registration is disabled in IdRegistry, but enabled in NameRegistry and
@@ -342,12 +337,7 @@ contract BundleRegistryTest is Test {
342337
TRUSTED REGISTER TESTS
343338
//////////////////////////////////////////////////////////////*/
344339

345-
function testTrustedRegister(
346-
address alice,
347-
address recovery,
348-
string calldata url,
349-
uint256 inviter
350-
) public {
340+
function testTrustedRegister(address alice, address recovery, string calldata url, uint256 inviter) public {
351341
vm.assume(alice != address(0)); // OZ's ERC-721 throws when a zero-address mints an NFT
352342

353343
// State: Trusted registration is enabled in both registries and trusted caller is set in both
@@ -449,11 +439,7 @@ contract BundleRegistryTest is Test {
449439
TRUSTED BATCH REGISTER TESTS
450440
//////////////////////////////////////////////////////////////*/
451441

452-
function testTrustedBatchRegister(
453-
address alice,
454-
address bob,
455-
address charlie
456-
) public {
442+
function testTrustedBatchRegister(address alice, address bob, address charlie) public {
457443
vm.assume(alice != address(0)); // OZ's ERC-721 throws when a zero-address mints an NFT
458444
vm.assume(bob != address(0)); // OZ's ERC-721 throws when a zero-address mints an NFT
459445
vm.assume(charlie != address(0)); // OZ's ERC-721 throws when a zero-address mints an NFT

0 commit comments

Comments
 (0)