devkanro / intellij-protobuf-plugin

IntelliJ-based IDEs Protobuf Language Plugin that provides Protobuf language support.
Apache License 2.0
83 stars 11 forks source link

Incorrect prefix suggestion for enums #123

Open clehene opened 2 years ago

clehene commented 2 years ago

"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.

devkanro commented 2 years ago

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 commented 2 years ago

It will relate to #45

clehene commented 2 years ago

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

devkanro commented 2 years ago

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.

charlie-amihan commented 10 months ago

+1 this rule is annoying af.