mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
Add ForceTypeAssert linter (#1789)
This commit is contained in:
parent
66fc779795
commit
5698d46e1f
5 changed files with 47 additions and 0 deletions
20
test/testdata/forcetypeassert.go
vendored
Normal file
20
test/testdata/forcetypeassert.go
vendored
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue