Skip to content

docs: add hints for go fix tool#849

Open
phm07 wants to merge 2 commits intomainfrom
go-fix-hints
Open

docs: add hints for go fix tool#849
phm07 wants to merge 2 commits intomainfrom
go-fix-hints

Conversation

@phm07
Copy link
Copy Markdown
Contributor

@phm07 phm07 commented May 8, 2026

This PR adds //go:fix inline hints to compatible deprecated functions. This makes it possible for the go fix tool to automatically replace deprecated members with their recommended alternative.

Example

Before

func foo() {
	client := hcloud.NewClient(hcloud.WithBackoffFunc(hcloud.ConstantBackoff(5 * time.Second)))
	client = hcloud.NewClient(hcloud.WithPollBackoffFunc(hcloud.ExponentialBackoff(2.0, 2)))
	client = hcloud.NewClient(hcloud.WithPollInterval(5 * time.Second))

	_, _ = client.Action.All(context.Background())

	floatingIP := &hcloud.FloatingIP{ID: 123}
	_ = floatingIP.DNSPtrForIP(net.IP{})

	_ = hcloud.String("abc")
	_ = hcloud.Duration(time.Second)
	_ = hcloud.Int(123)
	_ = hcloud.Bool(true)

	var err hcloud.Error
	if err.Code == hcloud.ErrorCodeLimitReached {
		/* ... */
	}

	var (
		_ hcloud.PrimaryIPAssignResult
		_ hcloud.PrimaryIPChangeDNSPtrResult
		_ hcloud.PrimaryIPChangeProtectionResult
	)
}

After go fix

func foo() {
	client := hcloud.NewClient(hcloud.WithRetryOpts(hcloud.RetryOpts{BackoffFunc: hcloud.ConstantBackoff(5 * time.Second)}))
	client = hcloud.NewClient(hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ExponentialBackoff(2.0, 2)}))
	client = hcloud.NewClient(hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ConstantBackoff(5 * time.Second)}))

	_, _ = client.Action.AllWithOpts(context.Background(), hcloud.ActionListOpts{ID: []int64{}})

	floatingIP := &hcloud.FloatingIP{ID: 123}
	_ = hcloud.IgnoreError(floatingIP.GetDNSPtrForIP(net.IP{}))

	_ = hcloud.Ptr("abc")
	_ = hcloud.Ptr(time.Second)
	_ = hcloud.Ptr(123)
	_ = hcloud.Ptr(true)

	var err hcloud.Error
	if err.Code == hcloud.ErrorCodeRateLimitExceeded {
		/* ... */
	}

	var (
		_ schema.PrimaryIPActionAssignResponse
		_ schema.PrimaryIPActionChangeDNSPtrResponse
		_ schema.PrimaryIPActionChangeProtectionResponse
	)
}

@phm07 phm07 requested a review from a team as a code owner May 8, 2026 11:50
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.29%. Comparing base (5bb7ba6) to head (f6c3b95).

Files with missing lines Patch % Lines
hcloud/client.go 0.00% 3 Missing ⚠️
hcloud/helper.go 0.00% 2 Missing ⚠️
hcloud/action.go 0.00% 1 Missing ⚠️
hcloud/floating_ip.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #849      +/-   ##
==========================================
- Coverage   78.39%   78.29%   -0.10%     
==========================================
  Files          60       60              
  Lines        4355     4358       +3     
==========================================
- Hits         3414     3412       -2     
- Misses        637      642       +5     
  Partials      304      304              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread hcloud/action.go
//go:fix inline
func (c *ActionClient) All(ctx context.Context) ([]*Action, error) {
return c.action.All(ctx, ActionListOpts{})
return c.AllWithOpts(ctx, ActionListOpts{ID: []int64{}})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added ID: []int64{} explicitly here to make clear that a list of IDs is expected. This function should have been broken for over a year anyway.

Comment thread hcloud/helper.go
//go:fix inline
func Duration(d time.Duration) *time.Duration { return Ptr(d) }

func IgnoreError[T any](t T, _ error) T {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper is necessary to make it possible to inline (*FloatingIP).DNSPtrForIP. If we don't want to export it we could consider moving it to exp/ (though there would be an import cycle if we moved it to errutil) or removing it entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant