Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent import order. #7

Open
stephennancekivell opened this issue Apr 22, 2022 · 0 comments
Open

Inconsistent import order. #7

stephennancekivell opened this issue Apr 22, 2022 · 0 comments

Comments

@stephennancekivell
Copy link

Hi, thanks for the project.

I noticed that when repeatedly running protoc with zap, the import order in the go code changes, despite nothing changing in the source proto files. It would be nice if it were always generating in the same order that gofmt sets.

For example with this small proto file.

main.proto

syntax = "proto3";

package test;

import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

If I run it twice, I get a diff like this.

-	_ "google.golang.org/protobuf/types/known/structpb"
-	_ "google.golang.org/protobuf/types/known/timestamppb"
+	_ "google.golang.org/protobuf/types/known/timestamppb"
+	_ "google.golang.org/protobuf/types/known/structpb"

A full log is below.

$ protoc --zap-marshaler_out=. main.proto && cat main.zap.go 
main.proto:5:1: warning: Import google/protobuf/struct.proto is unused.
main.proto:6:1: warning: Import google/protobuf/timestamp.proto is unused.
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: main.proto

package test

import (
	fmt "fmt"
	math "math"
	proto "github.com/golang/protobuf/proto"
	_ "google.golang.org/protobuf/types/known/timestamppb"      <<<<---- timestamp first
	_ "google.golang.org/protobuf/types/known/structpb"              <<<<---- structpb second
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

$ protoc --zap-marshaler_out=. main.proto && cat main.zap.go
main.proto:5:1: warning: Import google/protobuf/struct.proto is unused.
main.proto:6:1: warning: Import google/protobuf/timestamp.proto is unused.
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: main.proto

package test

import (
	fmt "fmt"
	math "math"
	proto "github.com/golang/protobuf/proto"
	_ "google.golang.org/protobuf/types/known/structpb"                <<<<---- structpb first
	_ "google.golang.org/protobuf/types/known/timestamppb"        <<<<---- timestamp second
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant