-
Notifications
You must be signed in to change notification settings - Fork 607
Update golangci-lint (1.46.2->1.50.0) #1416
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
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: oscr 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 |
|
Could we rebase the PR? I see that there are other changes as well which I think are not related to this PR |
|
@oscr Thanks for filing this PR! I think the presubmit is failing because you need to run |
c3acfaa to
50de140
Compare
|
@robscott Thank you! That seems to have solved it. |
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 @oscr!
| // - name: "version" | ||
| // value "v1" | ||
| // | ||
| // path: |
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.
Is this additional indentation required to pass the updated linter?
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 invoked golangci-lint with fix in in order to resolve the findings. I didn't add a Makefile target for it but it's quite useful. For example cluster-api has it: https://github.com/kubernetes-sigs/cluster-api/blob/1917d52af16a7df70c5e93c9bb0820d5c04f972f/Makefile#L478
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'm not sure how to fix this, but I think this is an example of the linter doing something we want to avoid. It's taking what would otherwise be valid inline YAML example and messing up the indentation to match golang indentation expectations. As far as the make rule that cluster-api has, I think that would actually address #1398. I'd be supportive of that kind of rule if we could figure out how to make it not break any inline examples we have.
Although I know inline yaml is generally not a good idea for go types, it does make our reference documentation much easier to follow: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io%2fv1alpha2.GRPCRouteRule.
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.
@robscott I can add the lint-fix target. No problem at all.
Given how gofmt insists on the current format is incorrect and want's the code reformatted, maybe we should just disable that specific linter and undo the changes? Whats your opinion on that?
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'm not sure, disabling all of gofmt for this relatively niche use case does seem unfortunate. We could possibly make an exception like this for gofmt that only applied to our API type definitions: https://github.com/kubernetes-sigs/gateway-api/blob/main/.golangci.yml#L42. Interested in what others think here as well.
/cc @shaneutt @youngnick
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 think we're stuck between two less than ideal options:
1. Don't run gofmt and goimports on our types files
This can be accomplished pretty easily with the following addition to exclude-rules:
- path: _types\.go
linters:
- gofmt
- goimports
It allows us to keep inline YAML examples in our godocs and therefore generated reference docs.
2. Remove YAML examples from inline docs
Although this may make our generated reference docs slightly harder to follow, it would ensure that our types files were well formatted.
3. Don't upgrade golangci-lint yet
This appears to pass with our current generation of golangci-lint which is only slightly older than this one.
At this point, I don't love any of the options, but am slightly leaning towards 3 here unless we can find a better alternative than 1 or 2.
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 think one thing to remember here is that many editors will format on save for Go. I can't remember explicitly enabling it (I might be wrong here) in IDEA but I nevertheless I have it. If the linter expects a certain indentation, but your tooling automatically reformats the code upon save, it's going to be a pain for contributors. I think there is a risk of many prs failing the lint step in the future.
Ultimately it's your call. I can fix 1, 2 or close it for 3.
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.
it's possible to embed yaml, just the entire block needs to be indented to conform to gofmt's notion of a code block
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.
From https://go.dev/doc/comment
indenting all the yaml by a tab should make it a preformatted code block
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.
Awesome find @seankhliao! Thank you so for your help here. I've updated the indents with tabs and at least locally it doesn't reformat or linting fail.
50de140 to
da48aee
Compare
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 the work on this @oscr!
| // - name: "version" | ||
| // value "v1" | ||
| // | ||
| // path: |
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'm not sure how to fix this, but I think this is an example of the linter doing something we want to avoid. It's taking what would otherwise be valid inline YAML example and messing up the indentation to match golang indentation expectations. As far as the make rule that cluster-api has, I think that would actually address #1398. I'd be supportive of that kind of rule if we could figure out how to make it not break any inline examples we have.
Although I know inline yaml is generally not a good idea for go types, it does make our reference documentation much easier to follow: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io%2fv1alpha2.GRPCRouteRule.
da48aee to
d4b188b
Compare
d4b188b to
2380e6c
Compare
2380e6c to
ce7a939
Compare
|
Newer version released. Updating pr with latest and greatest. |
e698894 to
039e8f4
Compare
039e8f4 to
71a6835
Compare
| // ``` | ||
| // matches: | ||
| // - method: | ||
| // type: Exact | ||
| // service: "foo" | ||
| // headers: | ||
| // - name: "version" | ||
| // value "v1" | ||
| // ``` |
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.
Unfortunately this didn't translate well to the generated reference docs 😢. https://deploy-preview-1416--kubernetes-sigs-gateway-api.netlify.app/references/spec/#gateway.networking.k8s.io%2fv1alpha2.GRPCRouteMatch. Not sure what the solution is, there likely is some combination of indentation that works well for most. I have noticed that inline yaml examples only seem to fail gofmt on top level structs/comments were the actual // is not indented.
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.
Unfortunate, but a good find with the top level comments. Is that a viable way forward? Otherwise I suggest closing the pr because it doesn't seem to be possible to move forward as is.
|
@oscr: 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. |
What type of PR is this?
/kind bug
/kind cleanup
What this PR does / why we need it:
Updates the golangci-lint version from 1.46.2 -> 1.49.0 and fixes all the findings. This is needed due to linters being disabled currently. Also adds
make linttarget which just makes it easier for developers.Here is the current main branch linter output:
Does this PR introduce a user-facing change?: