Skip to content

use-errors-new: disable for Go 1.26#1697

Merged
alexandear merged 3 commits intomgechev:masterfrom
alexandear:use-errors-new-disable-for-go126
Mar 25, 2026
Merged

use-errors-new: disable for Go 1.26#1697
alexandear merged 3 commits intomgechev:masterfrom
alexandear:use-errors-new-disable-for-go126

Conversation

@alexandear
Copy link
Copy Markdown
Collaborator

For unformatted strings, fmt.Errorf("x") in Go 1.26 allocates less and generally matches the allocations for errors.New("x"). See https://go.dev/doc/go1.26#fmtpkgfmt

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the use-errors-new lint rule to be effectively disabled for Go 1.26+ codebases, aligning the rule’s guidance with the Go 1.26 fmt.Errorf optimization for non-formatting usage.

Changes:

  • Skip use-errors-new analysis when the package Go version is at least 1.26.
  • Add Go 1.26 test fixtures (nested testdata/go1.26 module) to validate the rule is disabled.
  • Introduce a lint.Go126 version constant and extend the unit test to cover the new fixture.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rule/use_errors_new.go Adds Go 1.26+ early return to disable rule execution.
lint/package.go Adds Go126 version constant used by rules for version gating.
test/use_errors_new_test.go Runs the rule against the Go 1.26-scoped fixture.
testdata/go1.26/go.mod Declares a Go 1.26 nested module for version detection in tests.
testdata/go1.26/use_errors_new.go Fixture ensuring fmt.Errorf("literal") is not flagged under Go 1.26.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@denisvmedia denisvmedia left a comment

Choose a reason for hiding this comment

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

LGTM

@ccoVeille
Copy link
Copy Markdown
Contributor

What about something in the rules description file

@alexandear alexandear merged commit 67780da into mgechev:master Mar 25, 2026
10 checks passed
@alexandear alexandear deleted the use-errors-new-disable-for-go126 branch March 25, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants