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

error-strings does not allow multiple functions for the same package #1243

Open
leungster opened this issue Feb 19, 2025 · 3 comments · May be fixed by #1249
Open

error-strings does not allow multiple functions for the same package #1243

leungster opened this issue Feb 19, 2025 · 3 comments · May be fixed by #1249

Comments

@leungster
Copy link

Describe the bug
The error-strings rule uses the package name as the key to the errorFunctions map. If the arguments list has multiple functions under the same package like a.Wrap and a.New, the last function is linted against.

To Reproduce
Configure error-strings with error functions in the same package. e.g. errors.New will overwrite the default map.

Expected behavior
Allow multiple functions in the same package to be linted against.

@alexandear
Copy link
Contributor

Hi @leungster

Thank you for reporting this issue. To help us investigate further, could you please provide minimal steps to reproduce the problem? Specifically, we need a sample file with the relevant code and the actual/expected output.

For example:

Code:

// main.go
package main

import (
    "errors"
    "fmt"
)

func main() {
    err := errors.New("an error occurred")
    fmt.Println(err)
}

Configuration:

[rule.error-strings]
    arguments = ["errors.New"]

Actual:

$ revive main.go
// output showing the issue

Expected:

$ revive main.go
// expected output showing correct linting

@leungster
Copy link
Author

Test data:

// main.go
package main

import (
    "errors"
    "fmt"
)

func main() {
    err := errors.New("An error occurred!")
    fmt.Println(err)
}

Configuration

[rule.error-strings]
    arguments = ["errors.New", "errors.Wrap"]

Actual:

$ revive main.go
// no errors

Expected:

$ revive main.go
main.go:10:20: error strings should not be capitalized or end with punctuation or a newline

@alexandear
Copy link
Contributor

@leungster, thank you. I was able to reproduce and fix the bug.

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 a pull request may close this issue.

2 participants