Skip to content

feat(AIP-160): Add rule to validate filter field name - #1523

Merged
shwoodard merged 1 commit into
googleapis:mainfrom
shwoodard:aip160-filter-field-name
Aug 22, 2025
Merged

feat(AIP-160): Add rule to validate filter field name#1523
shwoodard merged 1 commit into
googleapis:mainfrom
shwoodard:aip160-filter-field-name

Conversation

@shwoodard

@shwoodard shwoodard commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

Validates that the field for filtering is called "filter" and not "filters" for List and custom methods' request messages.

@shwoodard
shwoodard requested review from a team and noahdietz August 20, 2025 20:56
@shwoodard
shwoodard force-pushed the aip160-filter-field-name branch from 783060f to 92a0d61 Compare August 20, 2025 21:02
Comment thread rules/aip0160/filter_field.go Outdated
@shwoodard
shwoodard force-pushed the aip160-filter-field-name branch from 92a0d61 to a76ef42 Compare August 21, 2025 11:31
@shwoodard shwoodard changed the title feat(AIP-160): Add rule to validate filter field. feat(AIP-160): Add rule to validate filter field name Aug 21, 2025
Comment thread rules/aip0160/filter_field_name.go Outdated

const (
nameMessageFmt = `Guidance: use the field, "string filter", not "string %s"`
nameSuggestion = "string filter"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this suggestion is applied to the location.DescriptorName it should be simply filter - we don't want to include the type in the suggestion that replaces the FieldDescriptorProto.name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread rules/aip0160/filter_field_name_test.go Outdated
FieldType string
FieldName string
MethodName string
err bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typical test pattern is to put problems testutils.Problems{} and just specify the desired finding or nil. I'm guessing this pattern was used to be more DRY?

I'm OK with keeping this as is, but maybe rename from err to invalid or something else since err is so commonly error in Go :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was modeled after TestCount in rules/aip0141/count_suffix_test.go. Nonetheless, good catch! I usually use wantError, but I didn't change it after I copied the aforementioned file.

Unless you feel strongly about including the testutils.Problems{} in the test cases, yes, I think it is more DRY this way.

Changed to wantError.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wantError is fine with me.

I personally prefer specifying the expected testutils.Problems in each test to avoid putting logic in tests (public TotT), but these tests are so simple I'm not too worried about it. Since we already have the pattern, we'd want to refactor and commit to one or the other wholesale, and one more won't hurt that refactor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noahdietz ftr, I don't know that the Go authors would agree with the TotT or at least that it applies in this scenario. IMO, keeping the repetition caused by having similar tesutils.Problems{} makes the files hard to read either by making the line length long or the table of tests very long. This makes the file harder to navigate. It doesn't seem like logic in the tests, but rather substitution. For these reasons, IMO, at least for table tests, the parameterized solution is preferable.

Validates that the field for filtering is called "filter" and not
"filters" for List and custom methods' request messages.
@shwoodard
shwoodard force-pushed the aip160-filter-field-name branch from a76ef42 to 5ecb260 Compare August 22, 2025 16:16
@shwoodard
shwoodard merged commit 73e4f83 into googleapis:main Aug 22, 2025
5 checks passed
@shwoodard
shwoodard deleted the aip160-filter-field-name branch August 22, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants