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

golangci should report deprecated code usage #971

Open
1 task done
fabriziosestito opened this issue Jan 20, 2025 · 1 comment
Open
1 task done

golangci should report deprecated code usage #971

fabriziosestito opened this issue Jan 20, 2025 · 1 comment
Assignees
Milestone

Comments

@fabriziosestito
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

While working on #967, we realized that the breaking change could have been anticipated since the webhook interfaces were already marked as deprecated. However, golangci did not detect this.

Expected Behavior

golangci should terminate with an error if deprecated code is used.

Steps To Reproduce

No response

Environment

Anything else?

No response

@fabriziosestito fabriziosestito changed the title golangci should report deprecated usage golangci should report deprecated code usage Jan 20, 2025
@kkaempf kkaempf added this to the 1.21 milestone Jan 20, 2025
@kkaempf kkaempf moved this to Todo in Kubewarden Jan 20, 2025
@jvanz jvanz self-assigned this Jan 21, 2025
@jvanz jvanz moved this from Todo to In Progress in Kubewarden Jan 21, 2025
@jvanz
Copy link
Member

jvanz commented Jan 22, 2025

There is no problem in our golinter configuration. The staticcheck linter is running and is able to detect deprecated code. I've tests adding deprecated comment in the vendor directory. For example, I've added the comment in the Add function in the Manager interface of the controller-runtime package. I can see this linter errors after that:

/home/jvanz/SUSE/kubewarden-controller/bin/golangci-lint-v1.60.3 run
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar. 
internal/controller/cert_controller.go:60:12: SA1019: mgr.Add is deprecated: testing. (staticcheck)
        if err := mgr.Add(r); err != nil {
                  ^

Than, I've discovered that the linter is not able to notify us about the deprecated types because the comment is not properly done. The deprecated comment should be in a seperated paragraph in the comments. In other words, it's:

// Defaulter defines functions for setting defaults on resources.
// Deprecated: Use CustomDefaulter instead.

But it should be:

// Defaulter defines functions for setting defaults on resources.
//
// Deprecated: Use CustomDefaulter instead.

After this change I can see the following linter errors:

api/policies/v1/admissionpolicy_webhook.go:48:7: SA1019: webhook.Defaulter is deprecated: Use CustomDefaulter instead. (staticcheck)
var _ webhook.Defaulter = &AdmissionPolicy{}
      ^
api/policies/v1/admissionpolicygroup_webhook.go:48:7: SA1019: webhook.Defaulter is deprecated: Use CustomDefaulter instead. (staticcheck)
var _ webhook.Defaulter = &AdmissionPolicyGroup{}
      ^
api/policies/v1/clusteradmissionpolicy_webhook.go:51:7: SA1019: webhook.Defaulter is deprecated: Use CustomDefaulter instead. (staticcheck)
var _ webhook.Defaulter = &ClusterAdmissionPolicy{}
      ^
api/policies/v1/clusteradmissionpolicygroup_webhook.go:50:7: SA1019: webhook.Defaulter is deprecated: Use CustomDefaulter instead. (staticcheck)
var _ webhook.Defaulter = &ClusterAdmissionPolicyGroup{}
      ^
api/policies/v1/policyserver_webhook.go:53:7: SA1019: webhook.Defaulter is deprecated: Use CustomDefaulter instead. (staticcheck)
var _ webhook.Defaulter = &PolicyServer{}

@jvanz jvanz moved this from In Progress to Pending review in Kubewarden Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Pending review
Development

No branches or pull requests

3 participants