Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(fmt): change default for override_spacing to false #4023

Merged

Conversation

PaulRBerg
Copy link
Contributor

@PaulRBerg PaulRBerg commented Jan 3, 2023

Motivation

The Solidity documentation uses no spacing between the override keyword and the overridden contract names:

contract Inherited is Base1, Base2
{
    // Derives from multiple bases defining foo(), so we must explicitly
    // override it
    function foo() public override(Base1, Base2) {}
}

Anecdotally, most Solidity code bases I've seen adhere to the same pattern where there is no spacing. This is perhaps the same reason why @benesjan opened issue #3522 in the first place.

Solution

Set the default value of variable_override_spacing to false.

Though, before this is merged in, we should fix #4025 first.

@mattsse mattsse requested a review from rkrasiuk January 3, 2023 22:58
@mattsse mattsse added the Cmd-forge-fmt Command: forge fmt label Jan 3, 2023
@rkrasiuk rkrasiuk added C-forge Command: forge A-config Area: config labels Jan 4, 2023
Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when there's no override target? i.e. it's just override because you have is Base1

@PaulRBerg PaulRBerg force-pushed the default-variable-override-spacing branch from eef54b5 to 24037c7 Compare January 6, 2023 09:44
@PaulRBerg
Copy link
Contributor Author

what happens when there's no override target?

I wanted to test this but unfortunately the newest override_spacing doesn't work anymore - setting to false doesn't remove the spacing now. This started happening immediately after upgrading to the latest version of Forge:

forge 0.2.0 (a44159a 2023-01-03T00:04:41.810446Z)

Cc-ing @rkrasiuk in case he can take a look?

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@PaulRBerg ugh, must be some config issue, looking

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@PaulRBerg the issue is unrelated, couple of latest releases failed
https://github.com/foundry-rs/foundry/actions/runs/3851356109

@PaulRBerg
Copy link
Contributor Author

Thanks, Roman, I will wait for the fix and try test again with only one base contract inherited.

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@PaulRBerg openssl got pulled into foundry again 😢 . we added a fix and CI check to prevent this from happening again. will re-release as soon as the fix is merged and ping you

@gakonst
Copy link
Member

gakonst commented Jan 6, 2023

image

what do we think of this?

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@gakonst in general, some tests need to be fixed with this change to mirror the default behavior. the exact issue on the screenshot is due to bad rendering. here's this branch on cli
Screenshot 2023-01-06 at 13 42 41

@rkrasiuk rkrasiuk changed the title refactor(fmt): change default for "variable_override_spacing" to true refactor(fmt): change default for override_spacing to false Jan 6, 2023
Copy link
Collaborator

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulRBerg there are some tests that need to be fixed to depict the changed default behavior. there are 3 override-spacing.fmt.sol files in testdata. the easiest way forward is to rename these to fmt.sol files and remove // config: override_spacing = false line (since this is now the default). the original fmt.sol files should be renamed to override-spacing.fmt.sol and should include // config: override_spacing = true at the top

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@PaulRBerg just checked, override_spacing option works on latest release 🫡

@PaulRBerg
Copy link
Contributor Author

Thanks for the quick turnaround, @rkrasiuk! I can confirm that override_spacing works in the latest release.

Re tests - thanks for the guidance! I have updated them to match the new default.

Copy link
Collaborator

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, will merge after checks pass

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 6, 2023

@PaulRBerg seems like some other files with default behavior need to be fixed as well

@PaulRBerg PaulRBerg force-pushed the default-variable-override-spacing branch 2 times, most recently from fd42b20 to 24037c7 Compare January 7, 2023 13:15
@PaulRBerg PaulRBerg force-pushed the default-variable-override-spacing branch from 24037c7 to 2fbe898 Compare January 7, 2023 13:20
@PaulRBerg
Copy link
Contributor Author

@rkrasiuk I took a look at the CI logs but I don't know what to make out of them .. I don't understand what went wrong. Looks like the "" formatting is the same as the ""?

Screenshot 2023-01-07 at 3 38 05 PM

@rkrasiuk
Copy link
Collaborator

rkrasiuk commented Jan 7, 2023

@PaulRBerg the CI logs do not show the space diff for some reason (see my response to @gakonst above). fixing the tests

@PaulRBerg
Copy link
Contributor Author

Oh, I see. Sorry for the back-and-forth, and thanks for the fix.

@rkrasiuk rkrasiuk merged commit a44aa13 into foundry-rs:master Jan 7, 2023
@PaulRBerg PaulRBerg deleted the default-variable-override-spacing branch January 7, 2023 16:47
PaulRBerg added a commit to PaulRBerg/foundry-template that referenced this pull request Jan 8, 2023
baolean pushed a commit to baolean/foundry that referenced this pull request Jan 26, 2023
davidadachi pushed a commit to davidadachi/foundry-template that referenced this pull request Oct 24, 2023
davidadachi pushed a commit to davidadachi/foundry-template that referenced this pull request Oct 24, 2023
dynaput247 added a commit to dynaput247/foundry-template that referenced this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-config Area: config C-forge Command: forge Cmd-forge-fmt Command: forge fmt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(fmt): unified override_spacing option for functions and state variables
4 participants