utils

package
v0.89.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractVarName

func ExtractVarName(expr ast.Expr) string

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

func GetExprAsString(expr ast.Expr) string

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

func GetIdentName(expr ast.Expr) string

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

func GetTypeName(expr ast.Expr) string

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

func GetTypeString(spec *ast.ValueSpec) string

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

func HasPositiveLength(pass *analysis.Pass, lengthArg ast.Expr) bool

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

func IsAllCaps(s string) bool

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

func IsBuiltinCall(call *ast.CallExpr, builtinName string) bool

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

func IsByteSlice(expr ast.Expr) bool

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

func IsByteSliceWithPass(pass *analysis.Pass, expr ast.Expr) bool

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

func IsGeneratedFile(file *ast.File) bool

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

func IsIdentCall(call *ast.CallExpr, name string) bool

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

func IsMakeByteSliceCall(call *ast.CallExpr) bool

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

func IsMakeCall(call *ast.CallExpr) bool

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

func IsMakeCallWithLength(call *ast.CallExpr, minArgs int) bool

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

func IsMakeMapCall(call *ast.CallExpr) bool

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

func IsMakeSliceCall(call *ast.CallExpr) bool

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

func IsMakeSliceZero(expr ast.Expr) bool

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

func IsMapType(expr ast.Expr) bool

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

func IsMapTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool

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

func IsMixedCaps(name string) bool

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

func IsReferenceType(expr ast.Expr) bool

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

func IsSliceOrMapType(expr ast.Expr) bool

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

func IsSliceOrMapTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool

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

func IsSliceType(expr ast.Expr) bool

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

func IsSliceTypeWithPass(pass *analysis.Pass, expr ast.Expr) bool

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

func IsSmallConstantSize(pass *analysis.Pass, expr ast.Expr) bool

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

func IsStructType(expr ast.Expr) bool

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

func IsTestFile(filename string) bool

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

func IsValidInitialism(name string) bool

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

func IsZeroLiteral(expr ast.Expr) bool

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

func ShouldSkipFile(pass *analysis.Pass, file *ast.File) bool

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

func ShouldSkipGeneratedFile(file *ast.File) bool

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

func ShouldSkipTestFile

func ShouldSkipTestFile(pass *analysis.Pass, file *ast.File) bool

ShouldSkipTestFile checks if a test file should be skipped. Only skips test files, not generated files.

Params:

  • pass: analysis pass
  • file: the AST file to check

Returns:

  • bool: true if the file is a test file

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL