From b8aeca11e1385797c7273d4ad2e10bb3869352f3 Mon Sep 17 00:00:00 2001 From: Edward McFarlane <3036610+emcfarlane@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:04:11 -0400 Subject: [PATCH] Force usage of private/pkg/protoencoding for text and yaml (#3347) --- .golangci.yml | 28 ++++++++++++++++++++-------- private/buf/bufcurl/invoker_test.go | 4 ++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 41ab9a24d6..f8eed63877 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,14 +22,10 @@ linters-settings: - '^print$' - '^println$' # Use private/pkg/protoencoding Marshalers and Unmarshalers - - '^proto.Marshal$' - - '^proto.Unmarshal$' - - '^proto.MarshalOptions$' - - '^proto.UnmarshalOptions$' - - '^protojson.Marshal$' - - '^protojson.Unmarshal$' - - '^protojson.MarshalOptions$' - - '^protojson.UnmarshalOptions$' + - '^(proto|prototext|protojson|protoyaml).Marshal$' + - '^(proto|prototext|protojson|protoyaml).Unmarshal$' + - '^(proto|prototext|protojson|protoyaml).MarshalOptions$' + - '^(proto|prototext|protojson|protoyaml).UnmarshalOptions$' govet: enable: - nilness @@ -378,3 +374,19 @@ issues: - forbidigo path: private/pkg/protoencoding text: "protojson.Unmarshal" + - linters: + - forbidigo + path: private/pkg/protoencoding + text: "protoyaml.Marshal" + - linters: + - forbidigo + path: private/pkg/protoencoding + text: "protoyaml.Unmarshal" + - linters: + - forbidigo + path: private/pkg/protoencoding + text: "prototext.Marshal" + - linters: + - forbidigo + path: private/pkg/protoencoding + text: "prototext.Unmarshal" diff --git a/private/buf/bufcurl/invoker_test.go b/private/buf/bufcurl/invoker_test.go index aecf6aad2d..af5193867f 100644 --- a/private/buf/bufcurl/invoker_test.go +++ b/private/buf/bufcurl/invoker_test.go @@ -19,10 +19,10 @@ import ( "os" "testing" + "github.com/bufbuild/buf/private/pkg/protoencoding" "github.com/bufbuild/protocompile" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -39,7 +39,7 @@ func TestCountUnrecognized(t *testing.T) { msg := msgType.New() msgData, err := os.ReadFile("./testdata/testdata.txt") require.NoError(t, err) - err = prototext.Unmarshal(msgData, msg.Interface()) + err = protoencoding.NewTxtpbUnmarshaler(nil).Unmarshal(msgData, msg.Interface()) require.NoError(t, err) // Add some unrecognized bytes unknownBytes := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1}