Search before asking
Description
Go 1.26 introduces improvements that enable more modern coding patterns.
During the go upgrade (#4597), the linter pointed out a ton of places where we can modernize the code and use new() (see the CI failure here). However, applying these changes requires careful review and testing to ensure correctness.
To avoid blocking the release, the newexpr check was temporarily disabled in golangci-lint.
This issue tracks re-enabling the newexpr check and updating the codebase accordingly to satisfy the linter.
Use case
Use Case
With the upgrade to Go 1.26, the golangci-lint newexpr check identifies opportunities to simplify pointer initialization by replacing helper utilities such as ptr.To(...) with the built-in new() function.
For example, existing code:
// /apiserver/pkg/model/converter_test.go line 296
EnableInTreeAutoscaling: ptr.To(true),
IdleTimeoutSeconds: ptr.To(int32(60)),
UpscalingMode: (*rayv1api.UpscalingMode)(ptr.To("Default")),
ImagePullPolicy: (*corev1.PullPolicy)(ptr.To("Always")),
can be simplified to:
EnableInTreeAutoscaling: new(true),
IdleTimeoutSeconds: new(int32(60)),
UpscalingMode: (*rayv1api.UpscalingMode)(new("Default")),
ImagePullPolicy: (*corev1.PullPolicy)(new("Always")),
This reduces dependency on k8s.io/utils/ptr and aligns the codebase with modern Go patterns.
Goal
Re-enable the newexpr linter check and update the codebase to replace usages of ptr.To(...) with new() where appropriate, ensuring correctness through testing.
Related issues
No response
Are you willing to submit a PR?
Search before asking
Description
Go 1.26 introduces improvements that enable more modern coding patterns.
During the go upgrade (#4597), the linter pointed out a ton of places where we can modernize the code and use
new()(see the CI failure here). However, applying these changes requires careful review and testing to ensure correctness.To avoid blocking the release, the
newexprcheck was temporarily disabled ingolangci-lint.This issue tracks re-enabling the
newexprcheck and updating the codebase accordingly to satisfy the linter.Use case
Use Case
With the upgrade to Go 1.26, the
golangci-lintnewexprcheck identifies opportunities to simplify pointer initialization by replacing helper utilities such asptr.To(...)with the built-innew()function.For example, existing code:
can be simplified to:
This reduces dependency on
k8s.io/utils/ptrand aligns the codebase with modern Go patterns.Goal
Re-enable the
newexprlinter check and update the codebase to replace usages ofptr.To(...)withnew()where appropriate, ensuring correctness through testing.Related issues
No response
Are you willing to submit a PR?