Skip to content

Commit

Permalink
Merge pull request #300 from yoheimuta/pluralized-rule-case-insensiti…
Browse files Browse the repository at this point in the history
…ve/294

fix: Make the pluralized rule check in the case-insensitive way
  • Loading branch information
yoheimuta authored Nov 19, 2022
2 parents a61ad84 + 8d482d3 commit 1a05b7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/addon/rules/repeatedFieldNamesPluralizedRule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rules

import (
"strings"

"github.com/yoheimuta/go-protoparser/v4/lexer"
"github.com/yoheimuta/go-protoparser/v4/lexer/scanner"
"github.com/yoheimuta/go-protoparser/v4/parser"
Expand Down Expand Up @@ -96,7 +98,7 @@ type repeatedFieldNamesPluralizedVisitor struct {
func (v *repeatedFieldNamesPluralizedVisitor) VisitField(field *parser.Field) bool {
got := field.FieldName
want := v.pluralizeClient.ToPlural(got)
if field.IsRepeated && got != want {
if field.IsRepeated && strings.ToLower(got) != strings.ToLower(want) {
v.AddFailuref(field.Meta.Pos, "Repeated field name %q must be pluralized name %q", got, want)

err := v.Fixer.SearchAndReplace(field.Meta.Pos, func(lex *lexer.Lexer) fixer.TextEdit {
Expand Down Expand Up @@ -125,7 +127,7 @@ func (v *repeatedFieldNamesPluralizedVisitor) VisitField(field *parser.Field) bo
func (v *repeatedFieldNamesPluralizedVisitor) VisitGroupField(field *parser.GroupField) bool {
got := field.GroupName
want := v.pluralizeClient.ToPlural(got)
if field.IsRepeated && got != want {
if field.IsRepeated && strings.ToLower(got) != strings.ToLower(want) {
v.AddFailuref(field.Meta.Pos, "Repeated group name %q must be pluralized name %q", got, want)

err := v.Fixer.SearchAndReplace(field.Meta.Pos, func(lex *lexer.Lexer) fixer.TextEdit {
Expand Down
20 changes: 20 additions & 0 deletions internal/addon/rules/repeatedFieldNamesPluralizedRule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ func TestRepeatedFieldNamesPluralizedRule_Apply(t *testing.T) {
},
},
},
{
name: "no failures for proto with valid field names considering the rule is case insensitive",
inputProto: &parser.Proto{
ProtoBody: []parser.Visitee{
&parser.Service{},
&parser.Message{
MessageBody: []parser.Visitee{
&parser.Field{
IsRepeated: true,
FieldName: "RunningOnDeviceIDS",
},
&parser.GroupField{
IsRepeated: true,
GroupName: "RunningOnDeviceIDs",
},
},
},
},
},
},
{
name: "no failures for proto with field names by applying some customization",
inputProto: &parser.Proto{
Expand Down

0 comments on commit 1a05b7f

Please sign in to comment.