golangci-lint/pkg/golinters/errorlint/testdata/errorlint_comparison.go
dependabot[bot] 9a7a1ad401
build(deps): bump github.com/polyfloyd/go-errorlint from 1.5.1 to 1.5.2 (#4785)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-06-01 16:24:17 +02:00

54 lines
1.5 KiB
Go

//golangcitest:args -Eerrorlint
//golangcitest:config_path testdata/errorlint_comparison.yml
package testdata
import (
"errors"
"log"
)
var errCompare = errors.New("foo")
func errorLintDoThing() error {
return errCompare
}
func errorLintComparison() {
err := errorLintDoThing()
if errors.Is(err, errCompare) {
log.Println("errCompare")
}
if err == nil {
log.Println("nil")
}
if err != nil {
log.Println("nil")
}
if nil == err {
log.Println("nil")
}
if nil != err {
log.Println("nil")
}
if err == errCompare { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error"
log.Println("errCompare")
}
if err != errCompare { // want "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error"
log.Println("not errCompare")
}
if errCompare == err { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error"
log.Println("errCompare")
}
if errCompare != err { // want "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error"
log.Println("not errCompare")
}
switch err {
case errCompare: // want "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors"
log.Println("errCompare")
}
switch errorLintDoThing() {
case errCompare: // want "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors"
log.Println("errCompare")
}
}