Skip to content

Commit

Permalink
Shifts to reduce lint warnings and internal build issues (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Nov 9, 2022
1 parent 218aabe commit e1a21ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
7 changes: 4 additions & 3 deletions common/types/pb/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (

func TestFileDescriptionGetExtensions(t *testing.T) {
pbdb := NewDb()
registerFileDescriptor(t, pbdb, proto2pb.File_test_proto2pb_test_all_types_proto)
registerFileDescriptor(t, pbdb, proto2pb.File_test_proto2pb_test_extensions_proto)
registerFileDescriptor(t, pbdb, &proto2pb.TestAllTypes{})
registerFileDescriptor(t, pbdb, &proto2pb.ExternalMessageType{})
ex, found := pbdb.DescribeType("google.expr.proto2.test.ExampleType")
if !found {
t.Fatal("ExampleType not found")
Expand Down Expand Up @@ -184,7 +184,8 @@ func TestFileDescriptionGetImportedEnumNames(t *testing.T) {
}
}

func registerFileDescriptor(t *testing.T, pbdb *Db, fileDesc protoreflect.FileDescriptor) {
func registerFileDescriptor(t *testing.T, pbdb *Db, pbMsg proto.Message) {
fileDesc := pbMsg.ProtoReflect().Descriptor().ParentFile()
_, err := pbdb.RegisterDescriptor(fileDesc)
if err != nil {
t.Fatalf("pbdb.RegisterDescriptor(%v) failed: %v", fileDesc, err)
Expand Down
12 changes: 6 additions & 6 deletions common/types/pb/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ func TestDbCopy(t *testing.T) {
if !reflect.DeepEqual(clone, clone2) {
t.Error("db.Copy() did not result in equivalent objects.")
}
_, err = clone.RegisterDescriptor(proto2pb.File_test_proto2pb_test_all_types_proto)
_, err = clone.RegisterMessage(&proto2pb.TestAllTypes{})
if err != nil {
t.Fatalf("Db.RegisterDescriptor() failed: %v", err)
t.Fatalf("Db.RegisterMessage() failed: %v", err)
}
if reflect.DeepEqual(clone, clone2) {
t.Error("clone modification altered derived clone2 also")
}

// modify the clone2 with some extensions and assert equivalence to clone3
_, err = clone2.RegisterDescriptor(proto2pb.File_test_proto2pb_test_all_types_proto)
_, err = clone2.RegisterMessage(&proto2pb.TestAllTypes{})
if err != nil {
t.Fatalf("Db.RegisterDescriptor() failed: %v", err)
t.Fatalf("Db.RegisterMessage() failed: %v", err)
}
_, err = clone2.RegisterDescriptor(proto2pb.File_test_proto2pb_test_extensions_proto)
_, err = clone2.RegisterMessage(&proto2pb.ExternalMessageType{})
if err != nil {
t.Fatalf("Db.RegisterDescriptor() failed: %v", err)
t.Fatalf("Db.RegisterMessage() failed: %v", err)
}
clone3 := clone2.Copy()
if !reflect.DeepEqual(clone2, clone3) {
Expand Down
38 changes: 19 additions & 19 deletions parser/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,83 +48,83 @@ func (p *parserHelper) getSourceInfo() *exprpb.SourceInfo {
MacroCalls: p.macroCalls}
}

func (p *parserHelper) newLiteral(ctx interface{}, value *exprpb.Constant) *exprpb.Expr {
func (p *parserHelper) newLiteral(ctx any, value *exprpb.Constant) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_ConstExpr{ConstExpr: value}
return exprNode
}

func (p *parserHelper) newLiteralBool(ctx interface{}, value bool) *exprpb.Expr {
func (p *parserHelper) newLiteralBool(ctx any, value bool) *exprpb.Expr {
return p.newLiteral(ctx,
&exprpb.Constant{ConstantKind: &exprpb.Constant_BoolValue{BoolValue: value}})
}

func (p *parserHelper) newLiteralString(ctx interface{}, value string) *exprpb.Expr {
func (p *parserHelper) newLiteralString(ctx any, value string) *exprpb.Expr {
return p.newLiteral(ctx,
&exprpb.Constant{ConstantKind: &exprpb.Constant_StringValue{StringValue: value}})
}

func (p *parserHelper) newLiteralBytes(ctx interface{}, value []byte) *exprpb.Expr {
func (p *parserHelper) newLiteralBytes(ctx any, value []byte) *exprpb.Expr {
return p.newLiteral(ctx,
&exprpb.Constant{ConstantKind: &exprpb.Constant_BytesValue{BytesValue: value}})
}

func (p *parserHelper) newLiteralInt(ctx interface{}, value int64) *exprpb.Expr {
func (p *parserHelper) newLiteralInt(ctx any, value int64) *exprpb.Expr {
return p.newLiteral(ctx,
&exprpb.Constant{ConstantKind: &exprpb.Constant_Int64Value{Int64Value: value}})
}

func (p *parserHelper) newLiteralUint(ctx interface{}, value uint64) *exprpb.Expr {
func (p *parserHelper) newLiteralUint(ctx any, value uint64) *exprpb.Expr {
return p.newLiteral(ctx, &exprpb.Constant{ConstantKind: &exprpb.Constant_Uint64Value{Uint64Value: value}})
}

func (p *parserHelper) newLiteralDouble(ctx interface{}, value float64) *exprpb.Expr {
func (p *parserHelper) newLiteralDouble(ctx any, value float64) *exprpb.Expr {
return p.newLiteral(ctx,
&exprpb.Constant{ConstantKind: &exprpb.Constant_DoubleValue{DoubleValue: value}})
}

func (p *parserHelper) newIdent(ctx interface{}, name string) *exprpb.Expr {
func (p *parserHelper) newIdent(ctx any, name string) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_IdentExpr{IdentExpr: &exprpb.Expr_Ident{Name: name}}
return exprNode
}

func (p *parserHelper) newSelect(ctx interface{}, operand *exprpb.Expr, field string) *exprpb.Expr {
func (p *parserHelper) newSelect(ctx any, operand *exprpb.Expr, field string) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_SelectExpr{
SelectExpr: &exprpb.Expr_Select{Operand: operand, Field: field}}
return exprNode
}

func (p *parserHelper) newPresenceTest(ctx interface{}, operand *exprpb.Expr, field string) *exprpb.Expr {
func (p *parserHelper) newPresenceTest(ctx any, operand *exprpb.Expr, field string) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_SelectExpr{
SelectExpr: &exprpb.Expr_Select{Operand: operand, Field: field, TestOnly: true}}
return exprNode
}

func (p *parserHelper) newGlobalCall(ctx interface{}, function string, args ...*exprpb.Expr) *exprpb.Expr {
func (p *parserHelper) newGlobalCall(ctx any, function string, args ...*exprpb.Expr) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_CallExpr{
CallExpr: &exprpb.Expr_Call{Function: function, Args: args}}
return exprNode
}

func (p *parserHelper) newReceiverCall(ctx interface{}, function string, target *exprpb.Expr, args ...*exprpb.Expr) *exprpb.Expr {
func (p *parserHelper) newReceiverCall(ctx any, function string, target *exprpb.Expr, args ...*exprpb.Expr) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_CallExpr{
CallExpr: &exprpb.Expr_Call{Function: function, Target: target, Args: args}}
return exprNode
}

func (p *parserHelper) newList(ctx interface{}, elements ...*exprpb.Expr) *exprpb.Expr {
func (p *parserHelper) newList(ctx any, elements ...*exprpb.Expr) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_ListExpr{
ListExpr: &exprpb.Expr_CreateList{Elements: elements}}
return exprNode
}

func (p *parserHelper) newMap(ctx interface{}, entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
func (p *parserHelper) newMap(ctx any, entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_StructExpr{
StructExpr: &exprpb.Expr_CreateStruct{Entries: entries}}
Expand All @@ -140,7 +140,7 @@ func (p *parserHelper) newMapEntry(entryID int64, key *exprpb.Expr, value *exprp
}
}

func (p *parserHelper) newObject(ctx interface{}, typeName string, entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
func (p *parserHelper) newObject(ctx any, typeName string, entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
exprNode := p.newExpr(ctx)
exprNode.ExprKind = &exprpb.Expr_StructExpr{
StructExpr: &exprpb.Expr_CreateStruct{
Expand All @@ -160,7 +160,7 @@ func (p *parserHelper) newObjectField(fieldID int64, field string, value *exprpb
}
}

func (p *parserHelper) newComprehension(ctx interface{}, iterVar string,
func (p *parserHelper) newComprehension(ctx any, iterVar string,
iterRange *exprpb.Expr,
accuVar string,
accuInit *exprpb.Expr,
Expand All @@ -180,15 +180,15 @@ func (p *parserHelper) newComprehension(ctx interface{}, iterVar string,
return exprNode
}

func (p *parserHelper) newExpr(ctx interface{}) *exprpb.Expr {
func (p *parserHelper) newExpr(ctx any) *exprpb.Expr {
id, isID := ctx.(int64)
if isID {
return &exprpb.Expr{Id: id}
}
return &exprpb.Expr{Id: p.id(ctx)}
}

func (p *parserHelper) id(ctx interface{}) int64 {
func (p *parserHelper) id(ctx any) int64 {
var location common.Location
switch ctx.(type) {
case antlr.ParserRuleContext:
Expand Down Expand Up @@ -562,7 +562,7 @@ func (e *exprHelper) OffsetLocation(exprID int64) common.Location {
var (
// Thread-safe pool of ExprHelper values to minimize alloc overhead of ExprHelper creations.
exprHelperPool = &sync.Pool{
New: func() interface{} {
New: func() any {
return &exprHelper{}
},
}
Expand Down

0 comments on commit e1a21ed

Please sign in to comment.