A pluggable linter and fixer to enforce Protocol Buffer style and conventions.
A pluggable linter and fixer to enforce Protocol Buffer style and conventions.
protolint is the pluggable linting/fixing utility for Protocol Buffer files (proto2+proto3):
Once MCP server configured, you can ask any MCP clients like Claude Desktop to lint and fix your Protocol Buffer files like this:
Also, vim-protolint works like the following.
protolint now includes support for the Model Context Protocol (MCP), which allows AI models to interact with protolint directly.
protolint --mcpFor detailed documentation on how to use and integrate protolint's MCP server functionality, see the MCP documentation.
protolint can be installed for Mac or Linux using Homebrew via the yoheimuta/protolint tap.
brew tap yoheimuta/protolint
brew install protolintSince homebrew-core includes protolint, you can also install it by just brew install protolint. This is the default tap that is installed by default. It's easier, but not maintained by the same author. To keep it updated, I recommend you run brew tap yoheimuta/protolint first.
You can also download a pre-built binary from this release page:
In the downloads section of each release, you can find pre-built binaries in .tar.gz packages.
protolint ships a Docker image yoheimuta/protolint that allows you to use protolint as part of your Docker workflow.
❯❯❯ docker run --volume "$(pwd):/workspace" --workdir /workspace yoheimuta/protolint lint _example/proto
[_example/proto/invalidFileName.proto:1:1] File name should be lower_snake_case.proto.
[_example/proto/issue_88/oneof_options.proto:11:5] Found an incorrect indentation style " ". " " is correct.
[_example/proto/issue_88/oneof_options.proto:12:5] Found an incorrect indentation style " ". " " is correct.The binary can be installed from source if Go is available. However, I recommend using one of the pre-built binaries instead because it doesn't include the version info.
go install github.com/yoheimuta/protolint/cmd/protolint@latestYou can use protolint using your nodejs package manager like npm or yarn.
$ npm install protolint --save-devThis will add a reference to a development dependency to your local package.json.
During install, the postinstall.js script will be called. It will download the matching protolint from github. Just like @electron/get, you can bypass the download using the following environment variables:
| Environment Variable | Default value | Description |
|---|---|---|
| PROTOLINT_MIRROR_HOST | https://github.com | HTTP/Web server base url hosting the binaries |
| PROTOLINT_MIRROR_REMOTE_PATH | yoheimuta/protolint/releases/download | Path to the archives on the remote host |
| PROTOLINT_MIRROR_USERNAME | HTTP Basic auth user name | |
| PROTOLINT_MIRROR_PASSWORD | HTTP Basic auth password | |
| PROTOLINT_PROXY | HTTP(S) Proxy with optional auth data |
Within the remote path, the archives from the releases page must be mirrored.
After that, you can use npx protolint (with all supplied protolint arguments) within your dev-scripts.
{
...
"scripts": {
"protoc": "....",
"preprotoc": "npx protolint"
},
...
}You can add a protolint node to your package.json which may contain the content of protolint.yml below the lint node, i.e. the root element of the configuration will be protolint.
If you want to get an output that matches the TSC compiler, use reporter tsc.
You can use protolint as a linter within your python projects, the wheel protolint-bin on pypi contains the pre-compiled binaries for various platforms. Just add the desired version to
your pyproject.toml or requirements.txt.
The wheels downloaded will contain the compiled go binaries for protolint and protoc-gen-protolint. Your platform must
be compatible with the supported binary platforms.
You can add the linter configuration to the tools.protolint package in pyproject.toml.
…protolint does not require configuration by default, for the majority of projects it should work out of the box.
protolint is available as a pre-commit hook. Add this to your .pre-commit-config.yaml in your repository to run protolint with Go:
repos:
- repo: https://github.com/yoheimuta/protolint
rev: v0.56.3 # Select a release here
hooks:
- id: protolintFor Docker-based execution, use the protolint-docker hook:
repos:
- repo: https://github.com/yoheimuta/protolint
hooks:
- id: protolint-docker # Uses yoheimuta/protolint:latest by defaultImportant: For Docker hooks, the rev parameter is meaningless for versioning per pre-commit's design. To pin to a specific protolint version, specify the Docker image tag in the entry:
repos:
- repo: https://github.com/yoheimuta/protolint
hooks:
- id: protolint-docker
entry: yoheimuta/protolint:v0.55.6 lint # Pin to specific versionVisual Studio Code
JetBrains IntelliJ IDEA, GoLand, WebStorm, PHPStorm, PyCharm...
Vim(ALE engine)
Vim(Syntastic)
A GitHub Action to run protolint in your workflows
Jenkins Plugins
Linters aggregator
It is possible to format your linting according to the formatting of the CI/CD environment. The environment must be set using the output format. Currently, the following output is realized:
| Environment | Command Line Value | Description | Example |
|---|---|---|---|
| Github Actions | ci-gh | Github Help | ::warning file=example.proto,line=10,col=20,title=ENUM_NAMES_UPPER_CAMEL_CASE::EnumField name \"SECOND.VALUE\" must be CAPITALS_WITH_UNDERSCORES |
| Azure DevOps | ci-az | Azure DevOps Help | ##vso[task.logissue type=warning;sourcepath=example.proto;linenumber=10;columnnumber=20;code=ENUM_NAMES_UPPER_CAMEL_CASE;]EnumField name \"SECOND.VALUE\" must be CAPITALS_WITH_UNDERSCORES |
| Gitlab CI/CD | ci-glab | Reverse Engineered from Examples | WARNING: ENUM_NAMES_UPPER_CAMEL_CASE example.proto(10,20) : EnumField name \"SECOND.VALUE\" must be CAPITALS_WITH_UNDERSCORES |
You can also use the generic ci formatter, which will create a generic problem matcher.
With the ci-env value, you can specify the template from the following environment variables:
| Environment Variable | Priority | Meaning |
|---|---|---|
| PROTOLINT_CIREPORTER_TEMPLATE_STRING | 1 | String containing a Go-template |
| PROTOLINT_CIREPORTER_TEMPLATE_FILE | 2 | Path to a file containing a Go-template |
The resulting line-feed must not be added, as it will be added automatically.
The following fields are available:
Severity
: The severity as string (either note, warning or error)
File
: Path to the file containing the error
Line
: Line within the file containing the error (starting position)
Column
: Column within the file containing the error (starting position)
Rule
: The name of the rule that is faulting
Message
: The error message that descibes the error
You can create a specific output matching your CI/CD environment and also create an output file, e.g. for your static code analysis tools like github CodeQL or SonarQube.
This can be done by adding the --add-reporter flag.
Please note, that the value must be formatted : (omitting ``).
$ protolint --reporter ci-gh --add-reporter sarif:/path/to/my/output.sarif.json proto/*.protoprotolint also maintains a binary protoc-gen-protolint that performs the lint functionality as a protoc plugin. See cmd/protoc-gen-protolint/README.md in detail.
This is useful in situations where you already have a protoc plugin workflow.
You can also use protolint from Go code. See Go Documentation and lib/lint_test.go in detail.
import (
"bytes"
"github.com/yoheimuta/protolint/lib"
)
func main() {
args := []string{"-config_path", "path/to/your_protolint.yaml", "."}
var stdout bytes.Buffer
var stderr bytes.Buffer
err := lib.Lint(args, &stdout, &stderr)
if err != nil {
// Handle error
}
// Process output in stdout and stderr
}See internal/addon/rules in detail.
The rule set follows:
No open issues yet, or sync has not completed.