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

feat(AIP-213): Lint message fields that should use common types #1297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

acamadeo
Copy link
Contributor

Part of #1130

@acamadeo acamadeo requested a review from a team as a code owner December 12, 2023 01:08
"color": "google.type.Color",
"colour": "google.type.Color",

"dollars": "google.type.Money",
Copy link
Contributor

Choose a reason for hiding this comment

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

for selecting common field names, I suggest using the public google API definitions here to identify commonly used patterns, for example: https://github.com/search?q=repo%3Agoogleapis%2Fgoogleapis+google.type.Money+lang%3Aproto&type=code

To give one specific example, for google.type.Money, I suggest dropping all proposed aliases, and instead just linting fields ending in "price", "cost", "_fee". you can look up the public google API repository here to see what commonly used patterns we use today: https://github.com/search?q=repo%3Agoogleapis%2Fgoogleapis+google.type.Money+lang%3Aproto&type=code

if the currency is implied by the field name we probably don't want to enforce using the Money type, since it's duplicating information and can lead to ambiguous / confusing behavior when the currency conflicts with the field name

also, "money" is very unlikely to be used as a field name, I have not seen examples of that. Perhaps "money_value" since it's used in 3 examples in public google APIs? https://github.com/search?q=repo%3Agoogleapis%2Fgoogleapis+%22google.type.Money+money%22+lang%3Aproto&type=code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

var commonTypesFields = &lint.FieldRule{
Name: lint.NewRuleName(213, "common-types-fields"),
LintField: func(f *desc.FieldDescriptor) []lint.Problem {
// Flag this field if it has a name in `fieldNameToCommonType` but
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest checking for postfixes instead of equality. It's common for fields to contain more than just the type, for example "background_color", "max_retry_duration"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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