intellij-protobuf-plugin icon indicating copy to clipboard operation
intellij-protobuf-plugin copied to clipboard

Incorrect prefix suggestion for enums

Open clehene opened this issue 1 year ago • 5 comments

"Value name of root enum should be start with enum name"

https://google.aip.dev/126

All enum values must use UPPER_SNAKE_CASE. The first value of the enum should be the name of the enum itself followed by the suffix _UNSPECIFIED. An exception to this rule is if there is a clearly useful zero value. In particular, if an enum needs to present an UNKNOWN, it is usually clearer and more useful for it to be a zero value rather than having both. The other values should not be prefixed by the name of the enum itself. This generally requires users to write MyState.MYSTATE_ACTIVE in their code, which is unnecessarily verbose.

clehene avatar Aug 20 '22 21:08 clehene

Note that some languages (including C++) hoist enum values into the parent namespace, which can result in conflicts for enums with the same values in the same proto package. To avoid this, multiple enums in the same proto package must not share any values. To avoid sharing values, APIs may prefix enum values with the name of the enum. In this case, they must do so consistently within the enum.

I make this rule by this note, maybe I need a setting page to config AIP spec.

devkanro avatar Aug 21 '22 15:08 devkanro

It will relate to #45

devkanro avatar Aug 21 '22 15:08 devkanro

@devkanro one thought - maybe it would make sense to externalize/delegate linting to a separate tool/config

clehene avatar Aug 21 '22 15:08 clehene

Separate tool can't provide quick fix advice (fix one file/ fix one line). I think it's worth integrating lint functionality into language plugins for smarter quick fixes. This plugin is still lacking in custom lint rules, something like the api-lint.yml will be useful.

devkanro avatar Aug 22 '22 02:08 devkanro