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 extrait le nom d'une variable depuis une expression complexe.
Params:
- expr: expression à analyser
Returns:
- string: nom de la variable ou représentation
func GetExprAsString ¶
GetExprAsString convertit une expression AST en sa représentation textuelle.
Params:
- expr: l'expression AST à convertir
Returns:
- string: la représentation textuelle (gère identifiants, sélecteurs, tableaux, maps, pointeurs, etc.)
func GetIdentName ¶
GetIdentName extrait le nom d'un identifiant depuis une expression.
Params:
- expr: expression à analyser
Returns:
- string: nom de l'identifiant ou chaîne vide
func GetTypeName ¶
GetTypeName extrait le nom d'un type depuis une expression.
Params:
- expr: l'expression représentant le type
Returns:
- string: le nom du type (ex: "map[string]int", "[]int", "chan int")
func GetTypeString ¶
GetTypeString extrait la représentation textuelle du type d'une ValueSpec.
Params:
- spec: la ValueSpec dont on veut extraire le type
Returns:
- string: la représentation textuelle du type, ou "<type>" si non spécifié
func HasPositiveLength ¶
HasPositiveLength vérifie si un argument de longueur est > 0.
Params:
- pass: contexte d'analyse
- lengthArg: argument de longueur
Returns:
- bool: true si la longueur est positive
func IsAllCaps ¶
IsAllCaps vérifie si une chaîne est entièrement en majuscules.
Params:
- s: la chaîne à vérifier
Returns:
- bool: true si au moins une lettre est présente et toutes sont en majuscules
func IsBuiltinCall ¶
IsBuiltinCall vérifie si c'est un appel à une fonction builtin.
Params:
- call: expression d'appel à vérifier
- builtinName: nom de la fonction builtin
Returns:
- bool: true si c'est un appel au builtin spécifié
func IsByteSlice ¶
IsByteSlice vérifie si un type est []byte via l'AST.
Params:
- expr: expression AST à vérifier
Returns:
- bool: true si c'est un []byte basé sur l'AST
func IsByteSliceWithPass ¶
IsByteSliceWithPass vérifie si un type est []byte.
Params:
- pass: contexte d'analyse
- expr: expression de type à vérifier
Returns:
- bool: true si c'est un []byte
func IsEmptySliceLiteral ¶
func IsEmptySliceLiteral(lit *ast.CompositeLit) bool
IsEmptySliceLiteral vérifie si un CompositeLit est un slice literal vide.
Params:
- lit: composite literal à vérifier
Returns:
- bool: true si c'est un slice literal vide ([]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 vérifie si un CallExpr est un appel à une fonction avec un nom spécifique.
Params:
- call: expression d'appel à vérifier
- name: nom de la fonction attendue
Returns:
- bool: true si c'est un appel à la fonction nommée
func IsMakeByteSliceCall ¶
IsMakeByteSliceCall vérifie si c'est un appel à make pour créer []byte.
Params:
- call: expression d'appel à vérifier
Returns:
- bool: true si c'est make([]byte, ...)
func IsMakeCall ¶
IsMakeCall vérifie si un CallExpr est un appel à make.
Params:
- call: expression d'appel à vérifier
Returns:
- bool: true si c'est un appel à make
func IsMakeCallWithLength ¶
IsMakeCallWithLength vérifie si c'est un appel à make avec une longueur spécifiée.
Params:
- call: expression d'appel à vérifier
- minArgs: nombre minimum d'arguments attendus
Returns:
- bool: true si c'est un appel à make avec au moins minArgs arguments
func IsMakeMapCall ¶
IsMakeMapCall vérifie si c'est un appel à make pour créer une map.
Params:
- call: expression d'appel à vérifier
Returns:
- bool: true si c'est make(map[K]V, ...)
func IsMakeSliceCall ¶
IsMakeSliceCall vérifie si c'est un appel à make pour créer un slice.
Params:
- call: expression d'appel à vérifier
Returns:
- bool: true si c'est make([]T, ...)
func IsMakeSliceZero ¶
IsMakeSliceZero vérifie si une expression est make([]T, 0) ou make([]T, 0, 0).
Params:
- expr: l'expression à vérifier
Returns:
- bool: true si c'est make([]T, 0) ou make([]T, 0, 0)
func IsMapType ¶
IsMapType vérifie si une expression est un type map en utilisant l'AST.
Params:
- expr: expression AST à vérifier
Returns:
- bool: true si c'est un type map basé sur l'AST
func IsMapTypeWithPass ¶
IsMapTypeWithPass vérifie si une expression est un type map en utilisant TypesInfo.
Params:
- pass: contexte d'analyse avec TypesInfo
- expr: expression à vérifier
Returns:
- bool: true si c'est un type map
func IsMixedCaps ¶
IsMixedCaps vérifie si un nom suit la convention MixedCaps/mixedCaps.
Params:
- name: le nom à valider
Returns:
- bool: true si valide (pas de snake_case, pas de ALL_CAPS sauf initialismes)
func IsReferenceType ¶
IsReferenceType vérifie si un type est un type référence (slice/map/chan).
Params:
- expr: l'expression représentant le type
Returns:
- bool: true si c'est un slice, map ou channel
func IsSliceOrMapType ¶
IsSliceOrMapType vérifie si une expression est un slice ou une map via AST.
Params:
- expr: expression AST à vérifier
Returns:
- bool: true si c'est un slice ou une map basé sur l'AST
func IsSliceOrMapTypeWithPass ¶
IsSliceOrMapTypeWithPass vérifie si une expression est un slice ou une map.
Params:
- pass: contexte d'analyse avec TypesInfo
- expr: expression à vérifier
Returns:
- bool: true si c'est un slice ou une map
func IsSliceType ¶
IsSliceType vérifie si un type est un slice.
Params:
- expr: l'expression représentant le type
Returns:
- bool: true si c'est un slice
func IsSliceTypeWithPass ¶
IsSliceTypeWithPass vérifie si une expression est un type slice en utilisant TypesInfo.
Params:
- pass: contexte d'analyse avec TypesInfo
- expr: expression à vérifier
Returns:
- bool: true si c'est un type slice
func IsSmallConstantSize ¶
IsSmallConstantSize vérifie si une expression est une constante <= 1024. Utilisé pour éviter que VAR-004/VAR-005 se déclenchent quand VAR-016 s'applique.
Params:
- pass: contexte d'analyse
- expr: expression de taille à vérifier
Returns:
- bool: true si c'est une constante positive <= 1024
func IsStructType ¶
IsStructType vérifie si un type est une struct.
Params:
- expr: l'expression représentant le type
Returns:
- bool: true si c'est une 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 vérifie si le nom est composé uniquement d'initialismes valides.
Params:
- name: le nom à vérifier
Returns:
- bool: true si composé uniquement d'initialismes valides
func IsZeroLiteral ¶
IsZeroLiteral vérifie si une expression est le literal zéro (0).
Params:
- expr: l'expression à vérifier
Returns:
- bool: true si c'est le 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.