Skip to content

Commit 5aa7546

Browse files
committed
group internal/... import paths as standard library
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.
1 parent 52739c5 commit 5aa7546

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Diff for: format/format.go

-2
Original file line numberDiff line numberDiff line change
@@ -978,10 +978,8 @@ func (f *fumpter) joinStdImports(d *ast.GenDecl) {
978978
case periodIndex > 0 && (slashIndex == -1 || periodIndex < slashIndex),
979979

980980
// "test" and "example" are reserved as per golang.org/issue/37641.
981-
// "internal" is unreachable.
982981
strings.HasPrefix(path, "test/"),
983982
strings.HasPrefix(path, "example/"),
984-
strings.HasPrefix(path, "internal/"),
985983

986984
// See if we match modulePrefix; see its documentation above.
987985
// We match either exactly or with a slash suffix,

Diff for: testdata/script/std-imports.txtar

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ import (
160160
// All of the extra imports below are known to not belong in std.
161161
// For example/ and test/, see https://golang.org/issue/37641.
162162
import (
163+
"internal/bar"
163164
"io"
164165

165166
"example/foo"
166-
"internal/bar"
167+
167168
"test/baz"
168169
)
169170

0 commit comments

Comments
 (0)