How to lint your Protocol Buffer files very quickly and easily

Yohei Yoshimuta
1 min readDec 27, 2018

I’m going to introduce the protolint.

A tool to enforce Protocol Buffer style and conventions.

- https://github.com/yoheimuta/protolint

prototool supports the rules following the Google style guide.

- https://developers.google.com/protocol-buffers/docs/style

❯❯❯ pl list
ENUM_FIELD_NAMES_UPPER_SNAKE_CASE: Verifies that all enum field names are CAPITALS_WITH_UNDERSCORES.
ENUM_NAMES_UPPER_CAMEL_CASE: Verifies that all enum names are CamelCase (with an initial capital).
FIELD_NAMES_LOWER_SNAKE_CASE: Verifies that all field names are underscore_separated_names.
MESSAGE_NAMES_UPPER_CAMEL_CASE: Verifies that all message names are CamelCase (with an initial capital).
RPC_NAMES_UPPER_CAMEL_CASE: Verifies that all rpc names are CamelCase (with an initial capital).
SERVICE_NAMES_UPPER_CAMEL_CASE: Verifies that all service names are CamelCase (with an initial capital).

Example:

❯❯❯ pl lint .
[v1/master/master.proto:30:5] Field name “shouldInvalidate” must be LowerSnakeCase
[v1/search/search.proto:45:5] Field name “brandEnds” must be LowerSnakeCase
[v1/support/marketing.proto:62:5] Field name “announcementInApp” must be LowerSnakeCase
[v1/support/marketing.proto:64:5] Field name “announcementApns” must be LowerSnakeCase
[v1/values/itemContentCondition.proto:35:5] EnumField name “Unidentified” must be UpperSnakeCase

You can disable rules in a Protocol Buffer file.
It is useful for projects which must keep API compatibility while enforce the style guide as much as possible.

// protolint:disable:next FIELD_NAMES_LOWER_SNAKE_CASE
bool brandEnds = 2;

bool shouldInvalidate = 1; // protolint:disable:this FIELD_NAMES_LOWER_SNAKE_CASE

.circleci/config.yaml example:

version: 2
jobs:
lint:
docker:
— image: circleci/golang:1.11.4
environment:
GO111MODULE: “on”
steps:
— checkout
— run:
name: Enforce Protocol Buffer style and conventions.
command: |
go get -u -v github.com/yoheimuta/protolint/cmd/pl
pl lint .
workflows:
version: 2
lint:
jobs:
— lint

protolint has a MIT License. Contributions and feedbacks welcome.

--

--