Skip to content

Commit 7011d38

Browse files
neilddsnet
authored andcommitted
protoc-gen-go: put all imports in one section (#720)
Keep plugin imports and non-plugin imports in the same section, but don't try to split stdlib and non-stdlib imports into different sections. Consistent with using astutil to insert all imports from a blank slate.
1 parent 7b18087 commit 7011d38

File tree

37 files changed

+40
-87
lines changed

37 files changed

+40
-87
lines changed

conformance/internal/conformance_proto/conformance.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonpb/jsonpb_test_proto/more_test_objects.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonpb/jsonpb_test_proto/test_objects.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/proto3_proto/proto3.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/test_proto/test.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-go/descriptor/descriptor.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-go/generator/generator.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,26 +1303,15 @@ func (g *Generator) generateImports() {
13031303
for importPath := range g.addedImports {
13041304
imports[importPath] = g.GoPackageName(importPath)
13051305
}
1306-
g.P("import (")
1307-
// Standard library imports.
1308-
g.P(g.Pkg["fmt"] + ` "fmt"`)
1309-
g.P(g.Pkg["math"] + ` "math"`)
1310-
for importPath, packageName := range imports {
1311-
if !strings.Contains(string(importPath), ".") {
1312-
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
1313-
}
1314-
}
1315-
g.P()
1316-
// Third-party imports.
1317-
//
13181306
// We almost always need a proto import. Rather than computing when we
13191307
// do, which is tricky when there's a plugin, just import it and
13201308
// reference it later. The same argument applies to the fmt and math packages.
1309+
g.P("import (")
1310+
g.P(g.Pkg["fmt"] + ` "fmt"`)
1311+
g.P(g.Pkg["math"] + ` "math"`)
13211312
g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
13221313
for importPath, packageName := range imports {
1323-
if strings.Contains(string(importPath), ".") {
1324-
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
1325-
}
1314+
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
13261315
}
13271316
g.P(")")
13281317
g.P()

protoc-gen-go/testdata/deprecated/deprecated.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-go/testdata/extension_base/extension_base.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-go/testdata/extension_extra/extension_extra.pb.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)