A structured log call is given a key without a value
What it finds
slog.Info("saved", "path", p, "size"): after the message, the logging functions of log/slog take keys and values in turns, so a key without a value is logged under the key !BADKEY and the record no longer says what it was meant to.
Checked are Debug, Info, Warn, Error, their Context forms and Log of log/slog, resolved through the imports. The arguments after the message are read in order: a call of one of the attribute functions of log/slog, such as slog.String, stands alone, and a constant string is a key that needs a value after it. The check stops at the first argument that is neither, since it may be an attribute held in a variable, and skips calls that pass args....
From the rule's source, slog_unpaired_argument.rs.
package p import ( "context" "log/slog") func f(ctx context.Context, path string, size int, attrs []any) { slog.Info("saved", "path", path, "size")tx0 reports: the key size has no value after it slog.Info("saved", "path", path, "size", size) slog.InfoContext(ctx, "saved", slog.String("path", path), "size")tx0 reports: the key size has no value slog.Warn("saved", attrs...) slog.Error("failed", "path", path, slog.Int("size", size))} 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:slog-unpaired-argument" = "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:slog-unpaired-argument] reason="..."tx0 explain tx0/go:slog-unpaired-argument shows the same in the terminal. Found a false positive? Report it.