Skip to content

Commit

Permalink
buf: add protobuf linting
Browse files Browse the repository at this point in the history
Adds protobuf linting hooks using Buf:
	https://docs.buf.build/

Expects buf to be installed locally.
  • Loading branch information
domodwyer committed Feb 15, 2021
1 parent 473748f commit 2dbd91a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
20 changes: 19 additions & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,22 @@
files: (?i)\.R$
pass_filenames: true
minimum_pre_commit_version: 0.15.0
description: 'Run lintr against R code'
description: 'Run lintr against R code'

- id: buf-lint
name: 'Lint protobuf files'
entry: buf-lint.sh
types: [proto]
language: 'script'
pass_filenames: false
minimum_pre_commit_version: 0.15.0
description: "Runs buf lint at the repo root"

- id: buf-breaking
name: 'Check protobuf for breaking changes'
entry: buf-breaking.sh
types: [proto]
language: 'script'
pass_filenames: false
minimum_pre_commit_version: 0.15.0
description: "Runs buf breaking at the repo root"
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Hooks:
* `rust-fmt`: runs `cargo fmt --all`
* `r-stylr`: runs [`stylr`] to format R code
* `r-lintr`: static analysis of R code with [`lintr`]
* `buf-lint`: runs [`buf`] lints against protobuf files
* `buf-breaking`: protobuf breaking change detection using [`buf`]

## Example config

Expand Down Expand Up @@ -64,7 +66,7 @@ repos:
stages: [commit, push]

- id: rust-clippy
#args: [ # Optionally override default configured lints
# args: [ # Optionally override default configured lints
# "-D rust_2018_idioms",
# "-D missing_docs",
#]
Expand All @@ -81,6 +83,15 @@ repos:

- id: r-lintr
stages: [commit, push]
stages: [commit, push]

- id: buf-lint
stages: [commit, push]

- id: buf-breaking
# Checks against 'master' branch by defaut, change with:
# args: [".git#tag=v1.0.0"]
stages: [commit, push]
```
## Tagged TODOs
Expand Down Expand Up @@ -129,4 +140,5 @@ When adding new hooks you can run `pre-commit try-repo .` for a quick syntax che
[dep]: https://github.com/golang/dep
[`post-checkout`]: https://git-scm.com/docs/githooks#_post_checkout
[`stylr`]: https://styler.r-lib.org/
[`lintr`]: https://github.com/jimhester/lintr
[`lintr`]: https://github.com/jimhester/lintr
[`buf`]: https://buf.build/
16 changes: 16 additions & 0 deletions buf-breaking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Protobuf breaking change detection with Buf: https://docs.buf.build/
#
# To run the checks locally:
# buf breaking
#
# To view the breaking change lints:
# buf config ls-breaking-rules

set -euo pipefail

# Default to checking against the local master Git branch
against=${1-'.git#branch=master'};

buf breaking "${against}"
13 changes: 13 additions & 0 deletions buf-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Protobuf linting with Buf: https://docs.buf.build/
#
# To run the lints locally:
# buf lint
#
# To view the available lints and their descriptions:
# buf config ls-lint-rules

set -euo pipefail

buf lint "$@"

0 comments on commit 2dbd91a

Please sign in to comment.