Skip to content

Commit ed6d9ce

Browse files
authored
Fix prefix trimming in struct-tag (#827)
Fix #813
1 parent 6d5bc51 commit ed6d9ce

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

rule/struct-tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string {
137137
case keyProtobuf:
138138
for _, option := range tag.Options {
139139
if strings.HasPrefix(option, "name=") {
140-
return strings.TrimLeft(option, "name=")
140+
return strings.TrimPrefix(option, "name=")
141141
}
142142
}
143143
return "" //protobuf tag lacks 'name' option

testdata/struct-tag.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type Simple struct {
116116
ODouble *float64 `protobuf:"fixed64,014,opt,name=o_double,json=oDouble"` // MATCH /duplicated tag number 14/
117117
ODoubleStr *float64 `protobuf:"fixed6,17,opt,name=o_double_str,json=oDoubleStr"` // MATCH /invalid protobuf tag name 'fixed6'/
118118
OString *string `protobuf:"bytes,18,opt,name=o_string,json=oString"`
119+
OString2 *string `protobuf:"bytes,name=ameno"`
120+
OString3 *string `protobuf:"bytes,name=ameno"` // MATCH /duplicate tag name: 'ameno'/
119121
XXX_NoUnkeyedLiteral struct{} `json:"-"`
120122
XXX_unrecognized []byte `json:"-"`
121123
XXX_sizecache int32 `json:"-"`

0 commit comments

Comments
 (0)