-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🌱 Improve Go formatting in CAPI codebase #8289
Conversation
Hi @abhay-krishna. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retitle 🌱 Improve Go formatting in CAPI codebase |
@abhay-krishna: Re-titling can only be requested by trusted users, like repository collaborators. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/retest |
/retest |
@abhay-krishna: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
I'm not able to reproduce the diff in the pull-cluster-api-verify-main presubmit. It expects the generated file to be the older unformatted code. I'm also sure how the jobs ran without an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for proposing this @abhay-krishna. I think if we want to include this we should at the least also use a linter - like we do for gofmt - to ensure the code stays to these standards.
I'm going to go through the actual changes made by the code, but the list of rules is at https://github.com/mvdan/gofumpt#added-rules
/ok-to-test
You should be able to fix this by running |
Thanks for the feedback @killianmuldoon! Yes, I intended to follow up with adding it to CI after getting initial feedback about this PR. I was going to suggest either adding it to golangci (so that it's covered in CI) and/or run gofumpt as a (pre-commit hook) [https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks] in Git (so that gofumpt is automatically run on every code change even if author might forget). We already use gofumpt in our golangci over on the EKS Anywhere repo so i can confirm it is fully supported and go ahead and add it in CAPI too. Interestingly enough, I ran make generate several times on a clean env but never got any net new diff, so I'm wondering what I'm missing. |
Interesting - when I run
These from the |
Adding it to golangci-lint probably works around the issue as make lint-fix should ignore the generated files (as they are on the ignore list of golangci-lint). Is there any way we can break this PR down to apply the fixes incrementally (by finding)? Would make it easier to decide if we agree with the opinions of gofumpt and also make the review flow easier (currently the PR touches a lot of files and it becames more fun when we have to rebase) |
@sbueringer Adding it to golangci did avoid linting the generated files, thanks!
I would like to, but I am not sure what incrementally means in this context. When I run make lint, I see only gofumpt issues and |
Unfortunately gofumpt doesn't seem to have a way to enable only a subset of its rules so I'm not sure how we would do this incrementally without making it a lot of work for everyone. |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest putting this on hold until the next release is cut.
Also, on top of the concern about the size of the PR, let's consider that enforcing formatting rules on top of what the go community defines as standard introduces a sort of friction for contributors not used to those rules, so It would be better if we can pick them selectively/after consider the value each rules brings in vs buy in all of them in one shot
Apologies for the size, I thought having all the relevant changes within a single PR would reduce churn and context switching for reviewers, and for the most part, the changes in this PR can be categorized into similar groups such as coalescing variable declaration blocks, newline additions between successive functions, short variable instantiations, etc, so I hope these changes would be less tedious to review than actual code changes. It's true that I do understand the friction that this could cause because, as Effective Go puts it,
But in favor of making the code more readable and keeping formatting consistent across all developers, I think we should enforce it in CI. |
Seems like the way forward is to go through the documented rules here: https://github.com/mvdan/gofumpt#added-rules and check if we agree with all of them. It was nice in case of other linters where we could just opt-in / opt-out if we didn't agree. IIRC I had a good experience with gofumpt in the past, but it has been a while |
That makes sense. For the context of this PR, the changes come under the following rules:
Most or all of these guidelines seem natural and reasonable to me since they fall under the formatting/linting practices that I (and others in my team) have been implementing, albeit manually from the start, later enforced by gofumpt. But I'll let the reviewers take their pick here. |
I think this makes sense - we should hold off merging this until after the 1.4 release ~March 28th. It shouldn't have much impact on this PR as I think the changes are, for the most part, automated. With regard to the rules - they seem to make sense, but I need to do a full review of this - especially given #8289 (comment) |
I'm cool with that. Until then I'll take care of rebasing it and fixing merge conflicts from time to time. |
@killianmuldoon This is ready for another review, thanks! |
Thanks for the bump! It will be a few days before I get around to this - I'll try to organise it so we have a couple of reviewers to do a short loop so this doesn't end up in rebase hell 😄 |
Thank you!! It hasn't been too bad, but I understand and appreciate your concern. |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
I think let's do the following. Let's get some basic agreement from a few folks that the rules described here are fine: https://github.com/mvdan/gofumpt#added-rules Once we have that, let's rebase the PR and do a quick round of review by 1-2 folks to make sure there are no suprises and then merge it. I personally just took a look and I'm fine with the rules gofumpt is enforcing. I think it makes the code more readable. It also pretty much matches my personal style, probably because I used gofumpt for a few years in the past :). I also think a few more rules are not a problem for new contributors as like today they can just run We had some discussions in the past about (too many) linters, let's see what other folks are saying. @CecileRobertMichon @enxebre @fabriziopandini @killianmuldoon @vincepri Any strong opinions either way? |
Agreed with all of this - I think gofumpt enforces a number of things that we tend to pick out in reviews - e.g. new lines. I'm +1 for including it. |
I'm 0 (neutral) on this PR; as I said in #8289 we should consider the toil for new contributors and it is not ideal to enable a block of controls without being able to pick them selectively/increamentally |
Closing due to inactivity. For posterity, we generally don't consider useful PRs that change just the style of the code which can be very subjective. /close |
@vincepri: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Before opening #8240, I ran the
gofumpt
tool as I do on all my Go changes, which made the following formatting fixes. Opened a separate PR for these changes in favor of separation of concerns.