Skip to content

Commit 2dbd91a

Browse files
committed
buf: add protobuf linting
Adds protobuf linting hooks using Buf: https://docs.buf.build/ Expects buf to be installed locally.
1 parent 473748f commit 2dbd91a

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,22 @@
118118
files: (?i)\.R$
119119
pass_filenames: true
120120
minimum_pre_commit_version: 0.15.0
121-
description: 'Run lintr against R code'
121+
description: 'Run lintr against R code'
122+
123+
- id: buf-lint
124+
name: 'Lint protobuf files'
125+
entry: buf-lint.sh
126+
types: [proto]
127+
language: 'script'
128+
pass_filenames: false
129+
minimum_pre_commit_version: 0.15.0
130+
description: "Runs buf lint at the repo root"
131+
132+
- id: buf-breaking
133+
name: 'Check protobuf for breaking changes'
134+
entry: buf-breaking.sh
135+
types: [proto]
136+
language: 'script'
137+
pass_filenames: false
138+
minimum_pre_commit_version: 0.15.0
139+
description: "Runs buf breaking at the repo root"

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Hooks:
1818
* `rust-fmt`: runs `cargo fmt --all`
1919
* `r-stylr`: runs [`stylr`] to format R code
2020
* `r-lintr`: static analysis of R code with [`lintr`]
21+
* `buf-lint`: runs [`buf`] lints against protobuf files
22+
* `buf-breaking`: protobuf breaking change detection using [`buf`]
2123

2224
## Example config
2325

@@ -64,7 +66,7 @@ repos:
6466
stages: [commit, push]
6567

6668
- id: rust-clippy
67-
#args: [ # Optionally override default configured lints
69+
# args: [ # Optionally override default configured lints
6870
# "-D rust_2018_idioms",
6971
# "-D missing_docs",
7072
#]
@@ -81,6 +83,15 @@ repos:
8183

8284
- id: r-lintr
8385
stages: [commit, push]
86+
stages: [commit, push]
87+
88+
- id: buf-lint
89+
stages: [commit, push]
90+
91+
- id: buf-breaking
92+
# Checks against 'master' branch by defaut, change with:
93+
# args: [".git#tag=v1.0.0"]
94+
stages: [commit, push]
8495
```
8596
8697
## Tagged TODOs
@@ -129,4 +140,5 @@ When adding new hooks you can run `pre-commit try-repo .` for a quick syntax che
129140
[dep]: https://github.com/golang/dep
130141
[`post-checkout`]: https://git-scm.com/docs/githooks#_post_checkout
131142
[`stylr`]: https://styler.r-lib.org/
132-
[`lintr`]: https://github.com/jimhester/lintr
143+
[`lintr`]: https://github.com/jimhester/lintr
144+
[`buf`]: https://buf.build/

buf-breaking.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
# Protobuf breaking change detection with Buf: https://docs.buf.build/
4+
#
5+
# To run the checks locally:
6+
# buf breaking
7+
#
8+
# To view the breaking change lints:
9+
# buf config ls-breaking-rules
10+
11+
set -euo pipefail
12+
13+
# Default to checking against the local master Git branch
14+
against=${1-'.git#branch=master'};
15+
16+
buf breaking "${against}"

buf-lint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
# Protobuf linting with Buf: https://docs.buf.build/
4+
#
5+
# To run the lints locally:
6+
# buf lint
7+
#
8+
# To view the available lints and their descriptions:
9+
# buf config ls-lint-rules
10+
11+
set -euo pipefail
12+
13+
buf lint "$@"

0 commit comments

Comments
 (0)