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

chore: gofumpt #11839

Merged
merged 9 commits into from
May 19, 2022
Merged

chore: gofumpt #11839

merged 9 commits into from
May 19, 2022

Conversation

faddat
Copy link
Contributor

@faddat faddat commented May 2, 2022

Description

I generated this pr using gofumpt

go install mvdan.cc/gofumpt@latest
gofumpt -w -l .

I find that it really does a great job of keeping things clean and
readable. Is it something we want to use?


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

Love the clean up, went through parts of the PR not everything due to size. Would love a second approval before merging.

@julienrbrt
Copy link
Member

julienrbrt commented May 2, 2022

Can this be as well added in .golangci.yml?

@alexanderbez
Copy link
Contributor

Didn't we have issues with this on Osmosis? What does this buy us over goimports which is natively supported by gopls and vscode?

@faddat
Copy link
Contributor Author

faddat commented May 2, 2022

@alexanderbez yep, we did.

I figure if we do it once in a while, we can get the benefits without the pain of having it in ci.

In ci, it could cause pain because then everyone must

gofumpt -w -l . every time

@ValarDragon mentioned it could be rough for first timers and I agree.

Also, I think it makes the code look and feel nicer.

Maybe do once in a while for a bit, and when the tooling/practice is more mature we add it to ci.

For example if it ran automatically when users:

golangci-lint run --fix ./... that'd be awesome

@amaury1093
Copy link
Contributor

Perhaps we can add gofumpt'ing the entire code to a script that we execute pre-releases and prior to making new major release branches?

I also think this is the best idea for now (suggestion from the osmosis issue)

@tac0turtle
Copy link
Member

@faddat do you want to add this in the release process?

@faddat
Copy link
Contributor Author

faddat commented May 6, 2022

@marbar3778 Sure!

@faddat
Copy link
Contributor Author

faddat commented May 7, 2022

@marbar3778 I've added gofumpt to the release process description document.

@faddat faddat force-pushed the faddat/gofumpt branch from fe95549 to de1469a Compare May 7, 2022 21:52
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

All changes checked. Approving as lgtm.

However, just a few nits. I think gofumpt made some formatting that is correct but not optimal due to the current formatting: when we were already line wrapping the arguments, gofumpt sometimes gets us one line with only one argument. IMHO we should then use only one line, or remove our manual wrapping and let gofumpt do its thing.

I think it'd be great to fix them before merging, as we are touching all those files anyway.

crypto/ledger/ledger_secp256k1.go Outdated Show resolved Hide resolved
server/config/config_test.go Show resolved Hide resolved
server/mock/app.go Outdated Show resolved Hide resolved
server/mock/app.go Outdated Show resolved Hide resolved
simapp/simd/cmd/root.go Outdated Show resolved Hide resolved
snapshots/chunk.go Outdated Show resolved Hide resolved
x/authz/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/authz/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/authz/keeper/keeper.go Outdated Show resolved Hide resolved
x/distribution/types/query.go Outdated Show resolved Hide resolved
x/distribution/types/query.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/client/testutil/test_helpers.go Outdated Show resolved Hide resolved
@faddat
Copy link
Contributor Author

faddat commented May 9, 2022

@julienrbrt -- I cannot exactly explain / justify changes maade by gofumpt -w -l .

Overall, I like what it does for the appearance and standardization of code, and you can check it out in more detail here:

https://github.com/mvdan/gofumpt

Sorry bout that

@julienrbrt
Copy link
Member

julienrbrt commented May 9, 2022

@julienrbrt -- I cannot exactly explain / justify changes maade by gofumpt -w -l .

Overall, I like what it does for the appearance and standardization of code, and you can check it out in more detail here:

https://github.com/mvdan/gofumpt

Sorry bout that

I understand, I use the tool as part of my workflow as well.
What I meant is that you can tweak how gofumpt will format lines by improving the formatting yourself first. My comments were suggestions where to do that:

For instance, in x/distribution/types/query.go we have:

func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward,
	total sdk.DecCoins) QueryDelegatorTotalRewardsResponse {
	return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total}
}

running gofumpt -w -l . on that will give us

func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward,
	total sdk.DecCoins,
) QueryDelegatorTotalRewardsResponse {
	return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total}
}

which is weird.

If before running gofumpt, we improve the styling to

func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward, total sdk.DecCoins) QueryDelegatorTotalRewardsResponse {
	return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total}
}

nothing will change, and we get, imo a better styling than with gofumpt.

I think it worth it to do that manual improving where we see gofumpt format the code with a one argument line.

@alexanderbez
Copy link
Contributor

alexanderbez commented May 9, 2022

I think I agree @julienrbrt. I should either be one line or each arg in a separate line. What gofumpt produces,

func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward,
	total sdk.DecCoins,
) QueryDelegatorTotalRewardsResponse {
	return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total}
}

Is not great. I'd rather see:

func NewQueryDelegatorTotalRewardsResponse(
	rewards []DelegationDelegatorReward,
	total sdk.DecCoins,
) QueryDelegatorTotalRewardsResponse {
	return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total}
}

@julienrbrt
Copy link
Member

@faddat Do you mind If I fix these nits myself in your branch?

@julienrbrt julienrbrt self-assigned this May 11, 2022
@faddat
Copy link
Contributor Author

faddat commented May 18, 2022

I don't mind at all :).

I am also wondering how else we can improve. Your nits were real.

aha!

OK, now that I have re-read your comments, it makes sense.

1st update:
I think I can find time tomorrow, or can give you access to our repo. Thanks a bunch for the review and suggestions!

2nd update:
thanks for the pr!

@julienrbrt
Copy link
Member

Thanks for updating!

@julienrbrt julienrbrt merged commit 5505428 into cosmos:main May 19, 2022
@crodriguezvega crodriguezvega mentioned this pull request May 23, 2022
9 tasks
@faddat faddat mentioned this pull request May 27, 2022
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* fumpt using main not master...

* be more descriptive

* fumpt

* fix nits

Co-authored-by: Julien Robert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants