A key is looked up before it is deleted, which delete does not need

tx0/go:guarded-deletestrictwarningstyle/conventionsdepth faststyle

What it finds

if _, ok := m[k]; ok { delete(m, k) }: delete does nothing when the key is missing, so the lookup before it only repeats the work. delete(m, k) alone does the same.

Reported is an if without else whose init statement is _, ok := m[k], whose condition is ok, and whose only statement is delete(m, k) of the same map and key.

From the rule's source, guarded_delete.rs.

Example from the rule's tests
package p func drop(m map[string]int, k string) {	if _, ok := m[k]; ok {tx0 reports: delete does nothing for a missing key; the lookup is not needed		delete(m, k)	}	if v, ok := m[k]; ok && v > 0 {		delete(m, k)	}}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:guarded-delete" = "warning"

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:guarded-delete] reason="..."

tx0 explain tx0/go:guarded-delete shows the same in the terminal. Found a false positive? Report it.