Skip to content

Commit

Permalink
Merge pull request #326 from yoheimuta/fix-uri-pluralize/312
Browse files Browse the repository at this point in the history
fix: Pluralize 'uri' properly
  • Loading branch information
yoheimuta authored Mar 7, 2023
2 parents 1df8bb8 + 5426fb7 commit 562afbf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ func TestRepeatedFieldNamesPluralizedRule_Apply(t *testing.T) {
},
},
},
{
name: "no failures for proto with field names including 'uri' by applying some customization internally",
inputProto: &parser.Proto{
ProtoBody: []parser.Visitee{
&parser.Service{},
&parser.Message{
MessageBody: []parser.Visitee{
&parser.Field{
IsRepeated: true,
FieldName: "uris",
},
&parser.Field{
IsRepeated: true,
FieldName: "module_uris",
},
},
},
},
},
},
{
name: "no failures for proto with field names by applying some customization",
inputProto: &parser.Proto{
Expand Down
5 changes: 4 additions & 1 deletion linter/strs/pluralize.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ type PluralizeClient struct {

// NewPluralizeClient creates a new client.
func NewPluralizeClient() *PluralizeClient {
return &PluralizeClient{
c := &PluralizeClient{
client: pluralize.NewClient(),
}
c.AddPluralRule("(?i)uri$", "uris")
c.AddSingularRule("(?i)uris$", "uri")
return c
}

// ToPlural converts the given string to its plural name.
Expand Down
4 changes: 4 additions & 0 deletions linter/strs/pluralize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func TestPluralizeClient_ToPlural(t *testing.T) {
{"PluralizeNonstandardPluralLatinWord", "cactuses", "cacti"},
{"PluralizePluralCamelCaseWord", "office_chairs", "office_chairs"},
{"PluralizeSingularCamelCaseWord", "office_chair", "office_chairs"},
{"special case #312: appends s to uri", "uri", "uris"},
{"special case #312: appends s to module_uri", "module_uri", "module_uris"},
{"special case #312: not change uris", "uris", "uris"},
{"special case #312: not change module_uris", "module_uris", "module_uris"},
}
for _, test := range tests {
test := test
Expand Down

0 comments on commit 562afbf

Please sign in to comment.