Skip to content

Commit fd31d18

Browse files
Minor refactor to update the format method name for go lint (#777)
1 parent 152a561 commit fd31d18

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

cel/env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ func FormatType(t *exprpb.Type) string {
9999
return checker.FormatCheckedType(t)
100100
}
101101

102-
// FormatCelType formats a cel.Type value to a string representation.
102+
// FormatCELType formats a cel.Type value to a string representation.
103103
//
104104
// The type formatting is identical to FormatType.
105-
func FormatCelType(t *Type) string {
106-
return checker.FormatCelType(t)
105+
func FormatCELType(t *Type) string {
106+
return checker.FormatCELType(t)
107107
}
108108

109109
// Env encapsulates the context necessary to perform parsing, type checking, or generation of

cel/env_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ERROR: <input>:1:2: Syntax error: mismatched input '<EOF>' expecting {'[', '{',
8484
}
8585
}
8686

87-
func TestFormatCelTypeEquivalence(t *testing.T) {
87+
func TestFormatCELTypeEquivalence(t *testing.T) {
8888
values := []*Type{
8989
AnyType,
9090
MapType(StringType, DynType),
@@ -95,14 +95,14 @@ func TestFormatCelTypeEquivalence(t *testing.T) {
9595
for _, v := range values {
9696
v := v
9797
t.Run(v.String(), func(t *testing.T) {
98-
celStr := FormatCelType(v)
98+
celStr := FormatCELType(v)
9999
et, err := TypeToExprType(v)
100100
if err != nil {
101101
t.Fatalf("TypeToExprType(%v) failed: %v", v, err)
102102
}
103103
exprStr := FormatType(et)
104104
if celStr != exprStr {
105-
t.Errorf("FormatCelType(%v) got %s, wanted %s", v, celStr, exprStr)
105+
t.Errorf("FormatCELType(%v) got %s, wanted %s", v, celStr, exprStr)
106106
}
107107
})
108108
}

cel/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func isOptionalIndex(i int, optIndices []int32) bool {
342342
}
343343

344344
func (homogeneousAggregateLiteralValidator) typeMismatch(iss *Issues, id int64, expected, actual *Type) {
345-
iss.ReportErrorAtID(id, "expected type '%s' but found '%s'", FormatCelType(expected), FormatCelType(actual))
345+
iss.ReportErrorAtID(id, "expected type '%s' but found '%s'", FormatCELType(expected), FormatCELType(actual))
346346
}
347347

348348
type nestingLimitValidator struct {

checker/errors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type typeErrors struct {
3131

3232
func (e *typeErrors) fieldTypeMismatch(id int64, l common.Location, name string, field, value *types.Type) {
3333
e.errs.ReportErrorAtID(id, l, "expected type of field '%s' is '%s' but provided type is '%s'",
34-
name, FormatCelType(field), FormatCelType(value))
34+
name, FormatCELType(field), FormatCELType(value))
3535
}
3636

3737
func (e *typeErrors) incompatibleType(id int64, l common.Location, ex *exprpb.Expr, prev, next *types.Type) {
@@ -46,7 +46,7 @@ func (e *typeErrors) noMatchingOverload(id int64, l common.Location, name string
4646

4747
func (e *typeErrors) notAComprehensionRange(id int64, l common.Location, t *types.Type) {
4848
e.errs.ReportErrorAtID(id, l, "expression of type '%s' cannot be range of a comprehension (must be list, map, or dynamic)",
49-
FormatCelType(t))
49+
FormatCELType(t))
5050
}
5151

5252
func (e *typeErrors) notAnOptionalFieldSelection(id int64, l common.Location, field *exprpb.Expr) {
@@ -67,12 +67,12 @@ func (e *typeErrors) referenceRedefinition(id int64, l common.Location, ex *expr
6767
}
6868

6969
func (e *typeErrors) typeDoesNotSupportFieldSelection(id int64, l common.Location, t *types.Type) {
70-
e.errs.ReportErrorAtID(id, l, "type '%s' does not support field selection", FormatCelType(t))
70+
e.errs.ReportErrorAtID(id, l, "type '%s' does not support field selection", FormatCELType(t))
7171
}
7272

7373
func (e *typeErrors) typeMismatch(id int64, l common.Location, expected, actual *types.Type) {
7474
e.errs.ReportErrorAtID(id, l, "expected type '%s' but found '%s'",
75-
FormatCelType(expected), FormatCelType(actual))
75+
FormatCELType(expected), FormatCELType(actual))
7676
}
7777

7878
func (e *typeErrors) undefinedField(id int64, l common.Location, field string) {

checker/format.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ func FormatCheckedType(t *exprpb.Type) string {
103103

104104
type formatter func(any) string
105105

106-
// FormatCelType formats a types.Type value to a string representation.
106+
// FormatCELType formats a types.Type value to a string representation.
107107
//
108108
// The type formatting is identical to FormatCheckedType.
109-
func FormatCelType(t any) string {
109+
func FormatCELType(t any) string {
110110
dt := t.(*types.Type)
111111
switch dt.Kind() {
112112
case types.AnyKind:
@@ -135,7 +135,7 @@ func FormatCelType(t any) string {
135135
}
136136
paramTypeNames := make([]string, 0, len(dt.Parameters()))
137137
for _, p := range dt.Parameters() {
138-
paramTypeNames = append(paramTypeNames, FormatCelType(p))
138+
paramTypeNames = append(paramTypeNames, FormatCELType(p))
139139
}
140140
return fmt.Sprintf("%s(%s)", dt.TypeName(), strings.Join(paramTypeNames, ", "))
141141
}
@@ -152,7 +152,7 @@ func formatFunctionExprType(resultType *exprpb.Type, argTypes []*exprpb.Type, is
152152
}
153153

154154
func formatFunctionDeclType(resultType *types.Type, argTypes []*types.Type, isInstance bool) string {
155-
return formatFunctionInternal[*types.Type](resultType, argTypes, isInstance, FormatCelType)
155+
return formatFunctionInternal[*types.Type](resultType, argTypes, isInstance, FormatCELType)
156156
}
157157

158158
func formatFunctionInternal[T any](resultType T, argTypes []T, isInstance bool, format formatter) string {

checker/format_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ func TestFormatType(t *testing.T) {
5151
if err != nil {
5252
t.Fatalf("types.TypeToExprType(%v) failed: %v", tc, err)
5353
}
54-
if FormatCelType(tc) != FormatCheckedType(exprType) {
55-
t.Errorf("formatCelType(%v) not equal to FormatCheckedType(%v), got %s, wanted %s",
56-
tc, exprType, FormatCelType(tc), FormatCheckedType(exprType))
54+
if FormatCELType(tc) != FormatCheckedType(exprType) {
55+
t.Errorf("FormatCELType(%v) not equal to FormatCheckedType(%v), got %s, wanted %s",
56+
tc, exprType, FormatCELType(tc), FormatCheckedType(exprType))
5757
}
5858
})
5959
}
6060
}
6161

6262
func TestFormatFunctionType(t *testing.T) {
6363
// native type representation of function(string, int) -> bool
64-
ct := FormatCelType(newFunctionType(types.BoolType, types.StringType, types.IntType))
64+
ct := FormatCELType(newFunctionType(types.BoolType, types.StringType, types.IntType))
6565
// protobuf-based function type
6666
et := FormatCheckedType(decls.NewFunctionType(decls.Bool, decls.String, decls.Int))
6767
if ct != et {
68-
t.Errorf("formatCelType() not equal to FormatCheckedType(), got %s, wanted %s", ct, et)
68+
t.Errorf("FormatCELType() not equal to FormatCheckedType(), got %s, wanted %s", ct, et)
6969
}
7070
}

checker/mapping.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func newMapping() *mapping {
2929
}
3030

3131
func (m *mapping) add(from, to *types.Type) {
32-
m.mapping[FormatCelType(from)] = to
32+
m.mapping[FormatCELType(from)] = to
3333
}
3434

3535
func (m *mapping) find(from *types.Type) (*types.Type, bool) {
36-
if r, found := m.mapping[FormatCelType(from)]; found {
36+
if r, found := m.mapping[FormatCELType(from)]; found {
3737
return r, found
3838
}
3939
return nil, false

0 commit comments

Comments
 (0)