A file has more than one import declaration

tx0/go:scattered-importsstrictwarningstyle

What it finds

import "fmt" followed by import "os": several import declarations in one file scatter what the file depends on, and gofmt and goimports sort and group only within one declaration. A single parenthesized declaration keeps the imports in one place.

Reported is every import declaration after the first. A separate declaration for import "C", which cgo requires on its own with its preamble, is left alone.

From the rule's source, scattered_imports.rs.

Example from the rule's tests
package p import "fmt" import "os"tx0 reports: the imports are split over several declarations func f() { fmt.Fprintln(os.Stdout) }
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:scattered-imports" = "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:scattered-imports] reason="..."

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