A file imports the same package twice under different names

tx0/go:duplicate-importrecommendedwarningmaintainability

What it finds

import ("net/http"; h "net/http"): both names refer to the same package, so readers meet two spellings for one thing and must check that they are the same. One import and one name suffice.

Imports with the same path are reported, unless one of them is a blank or dot import, which serve other purposes.

From the rule's source, duplicate_import.rs.

Example from the rule's tests
package p import (	"net/http"	web "net/http"tx0 reports: is already imported	_ "embed") var _ = http.StatusOK + web.StatusOK
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:duplicate-import" = "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:duplicate-import] reason="..."

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