Skip to content

Upgrade golangci-lint to v2 #7093

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

Open
antoninbas opened this issue Mar 31, 2025 · 6 comments
Open

Upgrade golangci-lint to v2 #7093

antoninbas opened this issue Mar 31, 2025 · 6 comments
Assignees
Labels
area/build-release Issues or PRs related to building and releasing good first issue Good for newcomers kind/task Categorizes issue or PR as related to a routine task that needs to be performed priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@antoninbas
Copy link
Contributor

golangci-lint has had a major version bump to v2
we should migrate to this new version
there is a migration guide available: https://golangci-lint.run/product/migration-guide/

@antoninbas antoninbas added area/build-release Issues or PRs related to building and releasing good first issue Good for newcomers kind/task Categorizes issue or PR as related to a routine task that needs to be performed priority/backlog Higher priority than priority/awaiting-more-evidence. labels Mar 31, 2025
@petertran-avgo petertran-avgo self-assigned this Apr 1, 2025
@petertran-avgo
Copy link
Contributor

Hey @antoninbas - I've been chipping away at this for a week now. Could I get your advice?

So far I've addressed all the staticcheck errors (on this branch https://github.com/petertran-avgo/antrea/commits/7093-bump-golang-ci-lint-v2/ ) which is pretty large.

There are 1157 remaining gosec issues:

  • 1113 of them are G104:

Errors unhandled (gosec)

Which is when a method returns an error but we don't check it. Here's an example:

https://github.com/antrea-io/antrea/blob/main/cmd/antrea-agent/agent.go#L382

informer.SetTransform(k8s.NewTrimmer(k8s.TrimPod)) // returns error but we don't check it
return informer

Do you think it would be okay to ignore G104? I havent looked at the remaining 43 issues but they should be much more manageable than g104

@antoninbas
Copy link
Contributor Author

I did the conversion recently for another smaller repository. When I used the conversion tool that golangci-lint provides, it automatically added the legacy preset which ignores G104: https://github.com/antrea-io/antrea-ui/blob/main/.golangci.yml#L29

I recommend using the conversion tool, focusing on moving to the v2 configuration, and trying to get to parity with what we have today (or as close as possible). If follow up changes are needed / desired (e.g., to enable more linters or rules, or to be more explicit about which rules are disabled), these changes should be performed in a separate PR IMO.

@petertran-avgo
Copy link
Contributor

Are you referring to the migrate sub-command?

@petertran-avgo
Copy link
Contributor

And thanks for the tip about legacy! Down to 36 gosec errors

@antoninbas
Copy link
Contributor Author

Are you referring to the migrate sub-command?

Yes. I'd suggest running that first. legacy should be added by default, or at least it was in my case.

@petertran-avgo
Copy link
Contributor

Thank you! Reflecting on this now, I recall the exclusions list having extra (at the time I thought) "directories" that didn't make sense to me that I removed. legacy must have been on there

petertran-avgo added a commit to petertran-avgo/antrea that referenced this issue May 7, 2025
* audited usage of unsafe to ensure it was done so correctly

Fixes antrea-io#7093

Signed-off-by: Peter Tran <peter-pt.tran@broadcom.com>
petertran-avgo added a commit to petertran-avgo/antrea that referenced this issue May 8, 2025
* audited usage of unsafe to ensure it was done so correctly

Fixes antrea-io#7093

Signed-off-by: Peter Tran <peter-pt.tran@broadcom.com>
petertran-avgo added a commit to petertran-avgo/antrea that referenced this issue May 8, 2025
* audited usage of unsafe to ensure it was done so correctly

Fixes antrea-io#7093

Signed-off-by: Peter Tran <peter-pt.tran@broadcom.com>
petertran-avgo added a commit to petertran-avgo/antrea that referenced this issue May 8, 2025
* audited usage of unsafe to ensure it was done so correctly

Fixes antrea-io#7093

Signed-off-by: Peter Tran <peter-pt.tran@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build-release Issues or PRs related to building and releasing good first issue Good for newcomers kind/task Categorizes issue or PR as related to a routine task that needs to be performed priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants