Schist

SCH052 Go autofix available

sort-imports

Flags an import block whose entries are not grouped by origin and sorted alphabetically within each group.

2 min read #imports#style#autofix

An unordered import block is harmless to the compiler and mildly costly to every reviewer after the first — diffs get noisier than they need to be when a new import lands in whatever position the author's editor happened to save it, and merge conflicts multiply when two branches add imports near each other. Schist groups imports into standard library and everything else, sorts each group alphabetically, and separates the groups with a single blank line, matching the convention goimports already established for the ecosystem.

Violation and fix

Violationrunner.go
import (
    "fmt"
    "schist/internal/lint"
    "os"
    "context"
)
Fixedrunner.go
import (
    "context"
    "fmt"
    "os"
​
    "schist/internal/lint"
)

schist/internal/lint is a local module import sitting in the middle of the standard-library group in the violation — Schist moves it into its own group below a blank line and re-sorts the standard-library entries around it, rather than just re-sorting in place, because a mixed group is itself the thing being flagged.

Autofix

Import reordering never changes which symbols are visible to the file, so this is one of the rules Schist autofixes by default; the patch is a pure reordering of existing lines with no new tokens introduced.

Configuration

[rules.sort-imports]
severity = "hint"
autofix = true
groups = ["stdlib", "local"]   # third-party imports would form a middle group if declared

Add a third group name to groups — commonly "third_party" — once a project vendors external modules; Schist detects module origin from the resolved import path, not from naming convention.

  • no-unused-import — the other rule that touches the same import block, run in the same autofix pass.
  • prefer-const-binding — another hint-severity rule with a mechanical, safe autofix.
  • Rules index — the full catalog in evaluation order.