A format and its arguments do not match
What it finds
Calls of the formatting functions of fmt and log whose format reads a different number of arguments than the call passes, and calls of their printing functions whose first argument contains a formatting directive, which they print as it is.
The package is resolved through the imports of the file, so an alias is followed and a local variable named fmt is not mistaken for it. Only constant formats are checked: string literals, their concatenations and constants declared in the file. A format that picks arguments by explicit index, as %[1]d does, is left alone, and so is a call that passes a slice with args....
From the rule's source, printf.rs.
package p import ( "errors" "fmt" "io" stdlog "log") const header = "%s: %d"const prefix = "id=%d " func g(w io.Writer, name string, n int, args []any) error { fmt.Printf("%s has %d items\n", name, n) fmt.Printf("%s has %d items\n", name)tx0 reports: fmt.Printf format reads 2 arguments, but 1 is given fmt.Printf("done\n", n)tx0 reports: reads 0 arguments, but 1 is given _ = fmt.Sprintf("%d%%", n) _ = fmt.Sprintf("%d%% of %d", n)tx0 reports: reads 2 arguments, but 1 is given _ = fmt.Sprintf("%*d|%-8.*f", 4, n, 2, 1.5) _ = fmt.Sprintf("%*d", n)tx0 reports: reads 2 arguments, but 1 is given _ = fmt.Sprintf("%[2]d %[1]d", n) _ = fmt.Sprintf("%v %v", args...) _ = fmt.Sprintf(header, name, n) _ = fmt.Sprintf(header, name)tx0 reports: reads 2 arguments, but 1 is given _ = fmt.Sprintf(prefix+header, 1, name, n) _ = fmt.Sprintf("\x25d", n) _ = fmt.Sprintf(`%s`)tx0 reports: reads 1 argument, but none is given fmt.Fprintf(w, "%d\n", n) fmt.Fprintf(w, "%d %d\n", n)tx0 reports: reads 2 arguments, but 1 is given stdlog.Printf("%s", name) stdlog.Fatalf("%s %s", name)tx0 reports: stdlog.Fatalf format reads 2 arguments fmt.Println("%d items", n)tx0 reports: fmt.Println prints %d as it is; fmt.Printf would format it fmt.Fprintln(w, "total: %v", n)tx0 reports: fmt.Fprintln prints %v stdlog.Print("50% done", "100%") fmt.Println("a%2Fb", "%%d") fmt.Println(name, "%d") if n > 0 { return fmt.Errorf("%s: %w", name, errors.New("x")) } return fmt.Errorf("%s: %w", name)tx0 reports: reads 2 arguments, but 1 is given} func shadowed(name string) { fmt := printer{} fmt.Printf("%s %s", name) log.Printf("%s %s", name)} type printer struct{} func (printer) Printf(string, ...any) {} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:printf" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:printf] reason="..."tx0 explain tx0/go:printf shows the same in the terminal. Found a false positive? Report it.