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

adds rule use-errors-new #1142

Merged
merged 1 commit into from
Nov 22, 2024
Merged

adds rule use-errors-new #1142

merged 1 commit into from
Nov 22, 2024

Conversation

chavacava
Copy link
Collaborator

Implementing a new rule use-errors-new that proposes replacing fmt.Errorf by errors.New when possible.

As indicated in this issue, beyond style considerations, errors.News is ~4x faster that fmt.Errorf

(initial discussion on this PR can be retrieved at #1136)

Comment on lines +47 to +49
if len(funcCall.Args) > 1 {
return w // the use of fmt.Errorf is legit
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, not exactly legit

We have crazy people out there

fmt.Errorf("%s, "whatever")
https://github.com/search?q=language%3Ago++%22fmt.Errorf%28%5C%22%25s%5C%22%2C+%5C%22%22&type=code

fmt.Errorf("%w", err)
https://github.com/search?q=language%3Ago++%22fmt.Errorf%28%5C%22%25w%5C%22%2C+%22&type=code

I created an issue on perfprint linter, as it's in their scope

I think you can merge like this, with current code.

My point can be addressed later

Originally posted by @ccoVeille in #1136 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was never my original goal to detect misuses like those because it implies too much complexity (less performance) to spot very veeeeery rare cases (written by people deserving to live with their own crazy code :) )

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this.

Maybe the comment could be updated to explain what you just wrote

@chavacava chavacava merged commit d2778f3 into master Nov 22, 2024
5 checks passed
@chavacava chavacava deleted the rule/use-errors-new branch February 4, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule proposal Issue proposing a new rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants