@@ -238,7 +238,7 @@ func checkAssignments(pass *analysis.Pass, list []ast.Stmt) bool {
238
238
239
239
case * ast.AssignStmt :
240
240
for i , val := range st .Rhs {
241
- if _ , isFunc := val .( * ast.FuncLit ); ! isFunc {
241
+ if ! is [ * ast.FuncLit ]( val ) {
242
242
if id , isIdent := st .Lhs [i ].(* ast.Ident ); isIdent && id .Name != "_" {
243
243
reportNoFix (pass , id .Pos (), useBeforeEachTemplate , id .Name )
244
244
foundSomething = true
@@ -268,7 +268,7 @@ func checkAssignments(pass *analysis.Pass, list []ast.Stmt) bool {
268
268
func checkAssignmentsValues (pass * analysis.Pass , names []* ast.Ident , values []ast.Expr ) bool {
269
269
foundSomething := false
270
270
for i , val := range values {
271
- if _ , isFunc := val .( * ast.FuncLit ); ! isFunc {
271
+ if ! is [ * ast.FuncLit ]( val ) {
272
272
reportNoFix (pass , names [i ].Pos (), useBeforeEachTemplate , names [i ].Name )
273
273
foundSomething = true
274
274
}
@@ -894,7 +894,7 @@ func handleEqualComparison(pass *analysis.Pass, matcher *ast.CallExpr, first ast
894
894
t := pass .TypesInfo .TypeOf (first )
895
895
if gotypes .IsInterface (t ) {
896
896
handler .ReplaceFunction (matcher , ast .NewIdent (beIdenticalTo ))
897
- } else if _ , ok := t .( * gotypes.Pointer ); ok {
897
+ } else if is [ * gotypes.Pointer ]( t ) {
898
898
handler .ReplaceFunction (matcher , ast .NewIdent (beIdenticalTo ))
899
899
} else {
900
900
handler .ReplaceFunction (matcher , ast .NewIdent (equal ))
@@ -1120,7 +1120,7 @@ func checkNilError(pass *analysis.Pass, assertionExp *ast.CallExpr, handler gome
1120
1120
}
1121
1121
1122
1122
var newFuncName string
1123
- if _ , ok := actualArg .( * ast.CallExpr ); ok {
1123
+ if is [ * ast.CallExpr ]( actualArg ) {
1124
1124
newFuncName = succeed
1125
1125
} else {
1126
1126
reverseAssertionFuncLogic (assertionExp )
@@ -1462,7 +1462,7 @@ func handleNilComparisonErr(pass *analysis.Pass, exp *ast.CallExpr, nilable ast.
1462
1462
newFuncName := beNil
1463
1463
isItError := isExprError (pass , nilable )
1464
1464
if isItError {
1465
- if _ , ok := nilable .( * ast.CallExpr ); ok {
1465
+ if is [ * ast.CallExpr ]( nilable ) {
1466
1466
newFuncName = succeed
1467
1467
} else {
1468
1468
reverseAssertionFuncLogic (exp )
@@ -1577,7 +1577,7 @@ func isComparison(pass *analysis.Pass, actualArg ast.Expr) (ast.Expr, ast.Expr,
1577
1577
case * ast.Ident : // check if const
1578
1578
info , ok := pass .TypesInfo .Types [realFirst ]
1579
1579
if ok {
1580
- if _ , ok := info . Type .( * gotypes.Basic ); ok && info .Value != nil {
1580
+ if is [ * gotypes.Basic ]( info . Type ) && info .Value != nil {
1581
1581
replace = true
1582
1582
}
1583
1583
}
@@ -1631,8 +1631,7 @@ func isExprError(pass *analysis.Pass, expr ast.Expr) bool {
1631
1631
1632
1632
func isPointer (pass * analysis.Pass , expr ast.Expr ) bool {
1633
1633
t := pass .TypesInfo .TypeOf (expr )
1634
- _ , ok := t .(* gotypes.Pointer )
1635
- return ok
1634
+ return is [* gotypes.Pointer ](t )
1636
1635
}
1637
1636
1638
1637
func isInterface (pass * analysis.Pass , expr ast.Expr ) bool {
@@ -1667,3 +1666,8 @@ func checkNoAssertion(pass *analysis.Pass, expr *ast.CallExpr, handler gomegahan
1667
1666
reportNoFix (pass , expr .Pos (), missingAssertionMessage , funcName , allowedFunction )
1668
1667
}
1669
1668
}
1669
+
1670
+ func is [T any ](x any ) bool {
1671
+ _ , matchType := x .(T )
1672
+ return matchType
1673
+ }
0 commit comments