protolint icon indicating copy to clipboard operation
protolint copied to clipboard

OneOf fields aren't linted

Open alexhayes opened this issue 2 years ago • 1 comments

While writing a custom rule FIELD_NAMES_CAMEL_CASE I discovered that oneof fields are not linted by the rule FIELD_NAMES_LOWER_SNAKE_CASE or FIELDS_HAVE_COMMENT.

For example, if you have;

syntax = "proto3";

message Foo {
  oneof MyField {
    string eggs = 1;
    string sausage = 2;
  }
}

This will pass linting even with the FIELD_NAMES_LOWER_SNAKE_CASE and/or FIELDS_HAVE_COMMENT enabled - when I'd expect it to complain about the MyField not being lower snake case and/or containing a comment.

Am I correct in thinking this is how it should behave or is that not the intended behaviour? It looks as if that's how it should behave.

alexhayes avatar Aug 03 '22 11:08 alexhayes

@alexhayes Thank you for reaching out.

I discovered that oneof fields are not linted by the rule

Oneof fields are string eggs = 1; and string sausage = 2;, not oneof MyField { }.

Style Guide mentions oneof field, but not oneof (name).

Regardless of that, your suggestion might be appropriate as Language Guide uses underscore_separated_names for oneof name. And it makes sense that protolint needs to provide a way to complain about the MyField not containing a comment at least. Meanwhile, I'm not sure oneof (not oneof fields) should be dealt with as fields. What do you think?

yoheimuta avatar Aug 06 '22 10:08 yoheimuta