From 5426fb7b303dfb16e40b95f394f50a245163be52 Mon Sep 17 00:00:00 2001 From: yoheimuta Date: Mon, 6 Mar 2023 19:42:11 +0900 Subject: [PATCH] fix: Pluralize 'uri' properly --- .../repeatedFieldNamesPluralizedRule_test.go | 20 +++++++++++++++++++ linter/strs/pluralize.go | 5 ++++- linter/strs/pluralize_test.go | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go b/internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go index 7f6129a9..85d92c90 100644 --- a/internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go +++ b/internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go @@ -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{ diff --git a/linter/strs/pluralize.go b/linter/strs/pluralize.go index b1f53ae8..8dc74f64 100644 --- a/linter/strs/pluralize.go +++ b/linter/strs/pluralize.go @@ -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. diff --git a/linter/strs/pluralize_test.go b/linter/strs/pluralize_test.go index 62b54e46..859bbd4d 100644 --- a/linter/strs/pluralize_test.go +++ b/linter/strs/pluralize_test.go @@ -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