Documentation
¶
Overview ¶
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Package utils provides AST utility functions for analyzers.
Index ¶
- func ExtractVarName(expr ast.Expr) string
- func GetExprAsString(expr ast.Expr) string
- func GetIdentName(expr ast.Expr) string
- func GetTypeName(expr ast.Expr) string
- func GetTypeString(spec *ast.ValueSpec) string
- func HasPositiveLength(pass *analysis.Pass, lengthArg ast.Expr) bool
- func IsAllCaps(s string) bool
- func IsBuiltinCall(call *ast.CallExpr, builtinName string) bool
- func IsByteSlice(expr ast.Expr) bool
- func IsByteSliceWithPass(pass *analysis.Pass, expr ast.Expr) bool
- func IsEmptySliceLiteral(lit *ast.CompositeLit) bool
- func IsGeneratedFile(file *ast.File) bool
- func IsIdentCall(call *ast.CallExpr, name string) bool
- func IsMakeByteSliceCall(call *ast.CallExpr) bool
- func IsMakeCall(call *ast.CallExpr) bool
- func IsMakeCallWithLength(call *ast.CallExpr, minArgs int) bool
- func IsMakeMapCall(call *ast.CallExpr) bool
- func IsMakeSliceCall(call *ast.CallExpr) bool
- func IsMakeSliceZero(expr ast.Expr) bool
- func IsMapType(expr ast.Expr) bool
- func IsMapTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool
- func IsMixedCaps(name string) bool
- func IsReferenceType(expr ast.Expr) bool
- func IsSliceOrMapType(expr ast.Expr) bool
- func IsSliceOrMapTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool
- func IsSliceType(expr ast.Expr) bool
- func IsSliceTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool
- func IsSmallConstantSize(pass *analysis.Pass, expr ast.Expr) bool
- func IsStructType(expr ast.Expr) bool
- func IsTestFile(filename string) bool
- func IsValidInitialism(name string) bool
- func IsZeroLiteral(expr ast.Expr) bool
- func ShouldSkipFile(pass *analysis.Pass, file *ast.File) bool
- func ShouldSkipGeneratedFile(file *ast.File) bool
- func ShouldSkipTestFile(pass *analysis.Pass, file *ast.File) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractVarName ¶
ExtractVarName extracts the variable name from a complex expression.
Params:
- expr: expression to analyze
Returns:
- string: variable name or representation
func GetExprAsString ¶
GetExprAsString converts an AST expression to its textual representation.
Params:
- expr: the AST expression to convert
Returns:
- string: the textual representation
func GetIdentName ¶
GetIdentName extracts the name of an identifier from an expression.
Params:
- expr: expression to analyze
Returns:
- string: identifier name or empty string
func GetTypeName ¶
GetTypeName extracts the type name from an expression.
Params:
- expr: the expression representing the type
Returns:
- string: the type name (e.g.: "map[string]int", "[]int", "chan int")
func GetTypeString ¶
GetTypeString extracts the textual representation of a ValueSpec's type.
Params:
- spec: the ValueSpec from which to extract the type
Returns:
- string: the textual representation of the type, or "<type>" if not specified
func HasPositiveLength ¶
HasPositiveLength checks if a length argument is > 0.
Params:
- pass: analysis context
- lengthArg: length argument
Returns:
- bool: true if the length is positive
func IsAllCaps ¶
IsAllCaps checks if a string is entirely uppercase.
Params:
- s: the string to check
Returns:
- bool: true if at least one letter is present and all are uppercase
func IsBuiltinCall ¶
IsBuiltinCall checks if it's a call to a builtin function.
Params:
- call: call expression to check
- builtinName: builtin function name
Returns:
- bool: true if it's a call to the specified builtin
func IsByteSlice ¶
IsByteSlice checks if a type is []byte via AST.
Params:
- expr: AST expression to check
Returns:
- bool: true if it is a []byte based on AST
func IsByteSliceWithPass ¶
IsByteSliceWithPass checks if a type is []byte.
Params:
- pass: analysis context
- expr: type expression to check
Returns:
- bool: true if it is a []byte
func IsEmptySliceLiteral ¶
func IsEmptySliceLiteral(lit *ast.CompositeLit) bool
IsEmptySliceLiteral checks if a CompositeLit is an empty slice literal.
Params:
- lit: composite literal to check
Returns:
- bool: true if it is an empty slice literal ([]T{})
func IsGeneratedFile ¶
IsGeneratedFile checks if a file is generated (contains "Code generated" comment).
Params:
- file: the AST file to check
Returns:
- bool: true if the file is generated
func IsIdentCall ¶
IsIdentCall checks if a CallExpr is a call to a function with a specific name.
Params:
- call: call expression to check
- name: expected function name
Returns:
- bool: true if it's a call to the named function
func IsMakeByteSliceCall ¶
IsMakeByteSliceCall checks if it's a make call to create []byte.
Params:
- call: call expression to check
Returns:
- bool: true if it's make([]byte, ...)
func IsMakeCall ¶
IsMakeCall checks if a CallExpr is a call to make.
Params:
- call: call expression to check
Returns:
- bool: true if it's a call to make
func IsMakeCallWithLength ¶
IsMakeCallWithLength checks if it's a make call with a specified length.
Params:
- call: call expression to check
- minArgs: minimum number of expected arguments
Returns:
- bool: true if it's a make call with at least minArgs arguments
func IsMakeMapCall ¶
IsMakeMapCall checks if it's a make call to create a map.
Params:
- call: call expression to check
Returns:
- bool: true if it's make(map[K]V, ...)
func IsMakeSliceCall ¶
IsMakeSliceCall checks if it's a make call to create a slice.
Params:
- call: call expression to check
Returns:
- bool: true if it's make([]T, ...)
func IsMakeSliceZero ¶
IsMakeSliceZero checks if an expression is make([]T, 0) or make([]T, 0, 0).
Params:
- expr: the expression to check
Returns:
- bool: true if it's make([]T, 0) or make([]T, 0, 0)
func IsMapType ¶
IsMapType checks if an expression is a map type using the AST.
Params:
- expr: AST expression to check
Returns:
- bool: true if it is a map type based on AST
func IsMapTypeWithPass ¶
IsMapTypeWithPass checks if an expression is a map type using TypesInfo.
Params:
- pass: analysis context with TypesInfo
- expr: expression to check
Returns:
- bool: true if it is a map type
func IsMixedCaps ¶
IsMixedCaps checks if a name follows the MixedCaps/mixedCaps convention.
Params:
- name: the name to validate
Returns:
- bool: true if valid (no snake_case, no ALL_CAPS except initialisms)
func IsReferenceType ¶
IsReferenceType checks if a type is a reference type (slice/map/chan).
Params:
- expr: the expression representing the type
Returns:
- bool: true if it's a slice, map or channel
func IsSliceOrMapType ¶
IsSliceOrMapType checks if an expression is a slice or a map via AST.
Params:
- expr: AST expression to check
Returns:
- bool: true if it is a slice or a map based on AST
func IsSliceOrMapTypeWithPass ¶
IsSliceOrMapTypeWithPass checks if an expression is a slice or a map.
Params:
- pass: analysis context with TypesInfo
- expr: expression to check
Returns:
- bool: true if it is a slice or a map
func IsSliceType ¶
IsSliceType checks if a type is a slice.
Params:
- expr: the expression representing the type
Returns:
- bool: true if it's a slice
func IsSliceTypeWithPass ¶
IsSliceTypeWithPass checks if an expression is a slice type using TypesInfo.
Params:
- pass: analysis context with TypesInfo
- expr: expression to check
Returns:
- bool: true if it is a slice type
func IsSmallConstantSize ¶
IsSmallConstantSize checks if an expression is a constant <= 1024. Used to avoid VAR-004/VAR-005 triggering when VAR-016 applies.
Params:
- pass: analysis context
- expr: size expression to check
Returns:
- bool: true if it is a positive constant <= 1024
func IsStructType ¶
IsStructType checks if a type is a struct.
Params:
- expr: the expression representing the type
Returns:
- bool: true if it's a struct
func IsTestFile ¶
IsTestFile checks if a file is a test file (*_test.go).
Params:
- filename: the file name to check
Returns:
- bool: true if the file is a test file
func IsValidInitialism ¶
IsValidInitialism checks if the name is composed only of valid initialisms.
Params:
- name: the name to check
Returns:
- bool: true if composed only of valid initialisms
func IsZeroLiteral ¶
IsZeroLiteral checks if an expression is the zero literal (0).
Params:
- expr: the expression to check
Returns:
- bool: true if it's the literal 0
func ShouldSkipFile ¶
ShouldSkipFile checks if a file should be skipped for analysis. Skips test files and generated files.
Params:
- pass: analysis pass
- file: the AST file to check
Returns:
- bool: true if the file should be skipped
func ShouldSkipGeneratedFile ¶
ShouldSkipGeneratedFile checks if a generated file should be skipped. Only skips generated files, not test files.
Params:
- file: the AST file to check
Returns:
- bool: true if the file is generated
Types ¶
This section is empty.