Skip to content

[Feature] Enable newexpr in the golangci-lint #4694

@hango880623

Description

@hango880623

Search before asking

  • I had searched in the issues and found no similar feature requirement.

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?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions