mirror of
https://github.com/mgechev/revive.git
synced 2025-05-31 22:49:41 +02:00
fix: avoid false positive for blank identifier (#1376)
The fact that the error variable is not used is out of the scope of the rule This pattern that can be found in benchmarks and examples. It should be allowed.
This commit is contained in:
parent
a56cf7290e
commit
a4737e935a
@ -61,6 +61,17 @@ func (w lintErrors) Visit(_ ast.Node) ast.Visitor {
|
||||
}
|
||||
|
||||
id := spec.Names[0]
|
||||
if id.Name == "_" {
|
||||
// avoid false positive for blank identifier
|
||||
|
||||
// The fact that the error variable is not used
|
||||
// is out of the scope of the rule
|
||||
|
||||
// This pattern that can be found in benchmarks and examples
|
||||
// should be allowed.
|
||||
continue
|
||||
}
|
||||
|
||||
prefix := "err"
|
||||
if id.IsExported() {
|
||||
prefix = "Err"
|
||||
|
12
testdata/golint/error_naming.go
vendored
12
testdata/golint/error_naming.go
vendored
@ -19,9 +19,19 @@ var (
|
||||
e1 = fmt.Errorf("blah %d", 4) // MATCH /error var e1 should have name of the form errFoo/
|
||||
// E2 ...
|
||||
E2 = fmt.Errorf("blah %d", 5) // MATCH /error var E2 should have name of the form ErrFoo/
|
||||
|
||||
// check there is no false positive for blank identifier.
|
||||
// This pattern that can be found in benchmarks and examples should be allowed.
|
||||
// The fact that the error variable is not used is out of the scope of this rule.
|
||||
_ = errors.New("ok")
|
||||
)
|
||||
|
||||
func f() {
|
||||
var whatever = errors.New("ok") // ok
|
||||
|
||||
// the linter does not check local variables, this one is valid
|
||||
var whatever = errors.New("ok")
|
||||
_ = whatever
|
||||
|
||||
// same as above with a blank identifier
|
||||
_ = errors.New("ok")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user