diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..96f3e27 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: check-merge-conflict + - id: check-json + - id: check-xml + - id: check-yaml + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer + exclude: ".svg$" + + - repo: local + hooks: + - id: make-fmt + name: Run make fmt + entry: make fmt + language: system + pass_filenames: false diff --git a/Makefile b/Makefile index 21c354f..c08d609 100755 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ #!/usr/bin/make -f SHELL=bash -.PHONY: doc +include help.mk + +.PHONY: doc fmt pre-commit unpre-commit pre-commit-run + # Regenerate documentation for proto files: doc: @for f in `find . -type f -name '*.proto' -exec dirname {} \; | sort -u `; do \ @@ -12,8 +15,21 @@ doc: --doc_out=proto-docs/ $${f}/*.proto; \ done +# Run clang-format fmt: @for f in `ls **/*.proto`; do \ echo "⇒ Formatting $$f"; \ clang-format -i $$f; \ done + +# Activate pre-commit hooks +pre-commit: + pre-commit install --hook-type pre-commit + +# Deactivate pre-commit hooks +unpre-commit: + pre-commit uninstall --hook-type pre-commit + +# Run pre-commit hooks +pre-commit-run: + @pre-commit run --all-files --hook-stage manual diff --git a/help.mk b/help.mk new file mode 100644 index 0000000..a2ac989 --- /dev/null +++ b/help.mk @@ -0,0 +1,11 @@ +.PHONY: help + +# Show this help prompt +help: + @echo ' Usage:' + @echo '' + @echo ' make ' + @echo '' + @echo ' Targets:' + @echo '' + @awk '/^#/{ comment = substr($$0,3) } /^[a-zA-Z][a-zA-Z0-9_-]+:/{ print " ", $$1, comment; comment = "" }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq