Add ForceTypeAssert linter (#1789)

This commit is contained in:
Ludovic Fernandez 2021-02-26 22:34:12 +01:00 committed by GitHub
parent 66fc779795
commit 5698d46e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 0 deletions

20
test/testdata/forcetypeassert.go vendored Normal file
View file

@ -0,0 +1,20 @@
//args: -Eforcetypeassert
package testdata
import "fmt"
func forcetypeassertInvalid() {
var a interface{}
_ = a.(int) // ERROR "type assertion must be checked"
var b interface{}
bi := b.(int) // ERROR "type assertion must be checked"
fmt.Println(bi)
}
func forcetypeassertValid() {
var a interface{}
if ai, ok := a.(int); ok {
fmt.Println(ai)
}
}