Skip to content

Commit

Permalink
group internal/... import paths as standard library
Browse files Browse the repository at this point in the history
The Go standard library includes internal packages such as
internal/testenv, and even though such packages cannot be imported
directly by users, they are still imported by std packages like os
and should be grouped with the rest of the std packages.

I can't recall what my logic was for excluding internal/ prefixes
from std grouping, but the logic no longer makes any sense to me.
This makes gofumpt less grumpy with how Go groups its own std imports.

Fixes #307.
  • Loading branch information
mvdan committed Jul 13, 2024
1 parent 52739c5 commit 5aa7546
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 0 additions & 2 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,8 @@ func (f *fumpter) joinStdImports(d *ast.GenDecl) {
case periodIndex > 0 && (slashIndex == -1 || periodIndex < slashIndex),

// "test" and "example" are reserved as per golang.org/issue/37641.
// "internal" is unreachable.
strings.HasPrefix(path, "test/"),
strings.HasPrefix(path, "example/"),
strings.HasPrefix(path, "internal/"),

// See if we match modulePrefix; see its documentation above.
// We match either exactly or with a slash suffix,
Expand Down
3 changes: 2 additions & 1 deletion testdata/script/std-imports.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ import (
// All of the extra imports below are known to not belong in std.
// For example/ and test/, see https://golang.org/issue/37641.
import (
"internal/bar"
"io"

"example/foo"
"internal/bar"

"test/baz"
)

Expand Down

0 comments on commit 5aa7546

Please sign in to comment.