mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
Fix #324, relates #314 1. Update gocritic to the latest version 2. Use proper gocritic checkers repo, old repo was archived 3. Get enabled by default gocritic checks in sync with go-critic: don't enable performance, experimental and opinionated checks by default 4. Support of `enabled-tags` options for gocritic 5. Enable almost all gocritic checks for the project 6. Make rich debugging for gocritic 7. Meticulously validate gocritic checks config
37 lines
1 KiB
Go
37 lines
1 KiB
Go
package lintutil
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/types"
|
|
)
|
|
|
|
// TODO: this package is a way to reuse code between lint and astwalk.
|
|
// Would be good to find it a better name.
|
|
|
|
// IsTypeExpr reports whether x represents type expression.
|
|
//
|
|
// Type expression does not evaluate to any run time value,
|
|
// but rather describes type that is used inside Go expression.
|
|
// For example, (*T)(v) is a CallExpr that "calls" (*T).
|
|
// (*T) is a type expression that tells Go compiler type v should be converted to.
|
|
func IsTypeExpr(info *types.Info, x ast.Expr) bool {
|
|
switch x := x.(type) {
|
|
case *ast.StarExpr:
|
|
return IsTypeExpr(info, x.X)
|
|
case *ast.ParenExpr:
|
|
return IsTypeExpr(info, x.X)
|
|
case *ast.SelectorExpr:
|
|
return IsTypeExpr(info, x.Sel)
|
|
case *ast.Ident:
|
|
// Identifier may be a type expression if object
|
|
// it reffers to is a type name.
|
|
_, ok := info.ObjectOf(x).(*types.TypeName)
|
|
return ok
|
|
|
|
case *ast.FuncType, *ast.StructType, *ast.InterfaceType, *ast.ArrayType, *ast.MapType:
|
|
return true
|
|
|
|
default:
|
|
return false
|
|
}
|
|
}
|