Functions
AFact
method
#
func (f *isWrapper) AFact()
Kind
method
#
Kind reports whether fn behaves like fmt.Print or fmt.Printf.
func (r *Result) Kind(fn *types.Func) Kind
Set
method
#
func (ss stringSet) Set(flag string) error
String
method
#
func (ss stringSet) String() string
String
method
#
func (kind Kind) String() string
String
method
#
func (f *isWrapper) String() string
argCanBeChecked
function
#
argCanBeChecked reports whether the specified argument is statically present;
it may be beyond the list of arguments or in a terminal slice... argument, which
means we can't see it.
func argCanBeChecked(pass *analysis.Pass, call *ast.CallExpr, formatArg int, state *formatState) bool
checkCalls
function
#
checkCalls triggers the print-specific checks for calls that invoke a print
function.
func checkCalls(pass *analysis.Pass)
checkPrint
function
#
checkPrint checks a call to an unformatted print routine such as Println.
func checkPrint(pass *analysis.Pass, call *ast.CallExpr, fn *types.Func)
checkPrintf
function
#
checkPrintf checks a call to a formatted print routine such as Printf.
func checkPrintf(pass *analysis.Pass, fileVersion string, kind Kind, call *ast.CallExpr, fn *types.Func)
checkPrintfFwd
function
#
checkPrintfFwd checks that a printf-forwarding wrapper is forwarding correctly.
It diagnoses writing fmt.Printf(format, args) instead of fmt.Printf(format, args...).
func checkPrintfFwd(pass *analysis.Pass, w *printfWrapper, call *ast.CallExpr, kind Kind, res *Result)
count
function
#
count(n, what) returns "1 what" or "N whats"
(assuming the plural of what is whats).
func count(n int, what string) string
findPrintfLike
function
#
findPrintfLike scans the entire package to find printf-like functions.
func findPrintfLike(pass *analysis.Pass, res *Result) (any, error)
formatStringIndex
function
#
formatStringIndex returns the index of the format string (the last
non-variadic parameter) within the given printf-like call
expression, or -1 if unknown.
func formatStringIndex(pass *analysis.Pass, call *ast.CallExpr) int
init
function
#
func init()
isConvertibleToString
function
#
func isConvertibleToString(typ types.Type) bool
isFormatter
function
#
isFormatter reports whether t could satisfy fmt.Formatter.
The only interface method to look for is "Format(State, rune)".
func isFormatter(typ types.Type) bool
isFunctionValue
function
#
isFunctionValue reports whether the expression is a function as opposed to a function call.
It is almost always a mistake to print a function value.
func isFunctionValue(pass *analysis.Pass, e ast.Expr) bool
isStringer
function
#
isStringer reports whether the method signature matches the String() definition in fmt.Stringer.
func isStringer(sig *types.Signature) bool
match
function
#
func match(info *types.Info, arg ast.Expr, param *types.Var) bool
match
method
#
match checks if typ matches m's printf arg type. If topLevel is true, typ is
the actual type of the printf arg, for which special rules apply. As a
special case, top level type parameters pass topLevel=true when checking for
matches among the constituents of their type set, as type arguments will
replace the type parameter at compile time.
func (m *argMatcher) match(typ types.Type, topLevel bool) bool
matchArgType
function
#
matchArgType reports an error if printf verb t is not appropriate for
operand arg.
If arg is a type parameter, the verb t must be appropriate for every type in
the type parameter type set.
func matchArgType(pass *analysis.Pass, t printfArgType, arg ast.Expr) (reason string, ok bool)
maybePrintfWrapper
function
#
maybePrintfWrapper decides whether decl (a declared function) may be a wrapper
around a fmt.Printf or fmt.Print function. If so it returns a printfWrapper
function describing the declaration. Later processing will analyze the
graph of potential printf wrappers to pick out the ones that are true wrappers.
A function may be a Printf or Print wrapper if its last argument is ...interface{}.
If the next-to-last argument is a string, then this may be a Printf wrapper.
Otherwise it may be a Print wrapper.
func maybePrintfWrapper(info *types.Info, decl ast.Decl) *printfWrapper
okPrintfArg
function
#
okPrintfArg compares the formatState to the arguments actually present,
reporting any discrepancies it can discern. If the final argument is ellipsissed,
there's little it can do for that.
func okPrintfArg(pass *analysis.Pass, call *ast.CallExpr, state *formatState) (ok bool)
parseFlags
method
#
parseFlags accepts any printf flags.
func (s *formatState) parseFlags()
parseIndex
method
#
parseIndex scans an index expression. It returns false if there is a syntax error.
func (s *formatState) parseIndex() bool
parseNum
method
#
parseNum scans a width or precision (or *). It returns false if there's a bad index expression.
func (s *formatState) parseNum() bool
parsePrecision
method
#
parsePrecision scans for a precision. It returns false if there's a bad index expression.
func (s *formatState) parsePrecision() bool
parsePrintfVerb
function
#
parsePrintfVerb looks the formatting directive that begins the format string
and returns a formatState that encodes what the directive wants, without looking
at the actual arguments present in the call. The result is nil if there is an error.
func parsePrintfVerb(pass *analysis.Pass, call *ast.CallExpr, name string, format string, firstArg int, argNum int) *formatState
printfNameAndKind
function
#
func printfNameAndKind(pass *analysis.Pass, call *ast.CallExpr) (fn *types.Func, kind Kind)
recursiveStringer
function
#
recursiveStringer reports whether the argument e is a potential
recursive call to stringer or is an error, such as t and &t in these examples:
func (t *T) String() string { printf("%s", t) }
func (t T) Error() string { printf("%s", t) }
func (t T) String() string { printf("%s", &t) }
func recursiveStringer(pass *analysis.Pass, e ast.Expr) (string, bool)
run
function
#
func run(pass *analysis.Pass) (any, error)
scanNum
method
#
scanNum advances through a decimal number if present.
func (s *formatState) scanNum()
stringConstantExpr
function
#
stringConstantExpr returns expression's string constant value.
("", false) is returned if expression isn't a string
constant.
func stringConstantExpr(pass *analysis.Pass, expr ast.Expr) (string, bool)