Skip to content

Commit

Permalink
Fix prefix trimming in struct-tag (#827)
Browse files Browse the repository at this point in the history
Fix #813
  • Loading branch information
mgechev authored May 16, 2023
1 parent 6d5bc51 commit ed6d9ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rule/struct-tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string {
case keyProtobuf:
for _, option := range tag.Options {
if strings.HasPrefix(option, "name=") {
return strings.TrimLeft(option, "name=")
return strings.TrimPrefix(option, "name=")
}
}
return "" //protobuf tag lacks 'name' option
Expand Down
2 changes: 2 additions & 0 deletions testdata/struct-tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ type Simple struct {
ODouble *float64 `protobuf:"fixed64,014,opt,name=o_double,json=oDouble"` // MATCH /duplicated tag number 14/
ODoubleStr *float64 `protobuf:"fixed6,17,opt,name=o_double_str,json=oDoubleStr"` // MATCH /invalid protobuf tag name 'fixed6'/
OString *string `protobuf:"bytes,18,opt,name=o_string,json=oString"`
OString2 *string `protobuf:"bytes,name=ameno"`
OString3 *string `protobuf:"bytes,name=ameno"` // MATCH /duplicate tag name: 'ameno'/
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Expand Down

0 comments on commit ed6d9ce

Please sign in to comment.