Skip to content

Commit

Permalink
fix: ignore proto3_optional fields in oneof check (#1370)
Browse files Browse the repository at this point in the history
When linting if a field is a oneof, ignore those fields that are proto3_optional, which are wrapped in a synthetic oneof.

Updates #1323
  • Loading branch information
noahdietz authored Apr 12, 2024
1 parent b92a828 commit 0d6e074
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/internal/utils/common_lints.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func LintFieldMask(f *desc.FieldDescriptor) []lint.Problem {

// LintNotOneof returns a problem if the field is a oneof.
func LintNotOneof(f *desc.FieldDescriptor) []lint.Problem {
if f.GetOneOf() != nil {
if f.GetOneOf() != nil && !f.IsProto3Optional() {
return []lint.Problem{{
Message: fmt.Sprintf("The `%s` field should not be a oneof field.", f.GetName()),
Descriptor: f,
Expand Down
1 change: 1 addition & 0 deletions rules/internal/utils/common_lints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func TestLintNotOneof(t *testing.T) {
problems testutils.Problems
}{
{"Valid", `string foo = 1;`, nil},
{"ValidProto3Optional", `optional string foo = 1;`, nil},
{"Invalid", `oneof foo_oneof { string foo = 1; }`, testutils.Problems{{Message: "should not be a oneof"}}},
} {
t.Run(test.testName, func(t *testing.T) {
Expand Down

0 comments on commit 0d6e074

Please sign in to comment.