Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore proto3_optional fields in oneof check #1370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading