The query of a URL is changed on a parsed copy that is then dropped
What it finds
u.Query().Set("page", "2"): Query of a url.URL parses the query string into a new url.Values each time it is called, so setting, adding or deleting a value on the result changes a copy that is dropped right away, and the URL keeps its old query. The values are kept in a variable, changed, and written back with u.RawQuery = q.Encode().
Reported are expression statements that call Set, Add or Del directly on the result of a method Query called without arguments, in a file that imports net/url or net/http.
From the rule's source, discarded_query_edit.rs.
package p import "net/url" func f(u *url.URL) string { u.Query().Set("page", "2")tx0 reports: Set changes a copy made by u.Query(), which is dropped q := u.Query() q.Set("page", "2") u.RawQuery = q.Encode() return u.String()} 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:discarded-query-edit" = "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:discarded-query-edit] reason="..."tx0 explain tx0/go:discarded-query-edit shows the same in the terminal. Found a false positive? Report it.