From f189ffe1507ad8beddbde919107a41f35fa19268 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Sat, 1 Jul 2023 18:23:57 -0400 Subject: [PATCH] add clang-format pre-commit hook (#4599) * Add a new YAML file (.pre-commit-config.yaml) to set up pre-commit hook for clang-format * The pre-commit hook is opt-in and needs to be installed in order to run automatically * Update CONTRIBUTING.md with instructions on how to set up and use the clang-format linter Automating the process of running clang-format before committing code helps to save time by removing the need to fix formatting issues later. This is a tooling improvement and doesn't change C++ code. --- .pre-commit-config.yaml | 6 ++++++ CONTRIBUTING.md | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..04893e956f0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +# .pre-commit-config.yaml +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v10.0.1 + hooks: + - id: clang-format diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a09ad4b991..8c9a81bb7b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,6 +121,11 @@ this: You can format individual files in place by running `clang-format -i ...` from any directory within this project. +You can install a pre-commit hook to automatically run `clang-format` before every commit: +``` +pip3 install pre-commit +pre-commit install +``` ## Avoid