This repository contains a pre-commit hook for formatting C++ and Metal shader files using clang-format
. It is designed to ensure consistent code styling by automatically formatting .cpp
, .h
, .hpp
, and .metal
files upon commit.
pre-commit
: This hook relies on the pre-commit framework. Ensure you havepre-commit
installed in your development environment.clang-format
: You must haveclang-format
installed on your system. This hook callsclang-format
directly to format the specified file types.
-
Install
pre-commit
(if not already installed):pip install pre-commit
or, if you prefer using Homebrew on macOS:
brew install pre-commit
-
Install
clang-format
(if not already installed):- On macOS:
brew install clang-format
- On Ubuntu:
sudo apt-get install clang-format
- On macOS:
-
Add the
clang-format-metal
hook to your project by creating or updating your.pre-commit-config.yaml
file in the root of your repository:repos: - repo: https://github.com/NripeshN/clang-format-metal rev: 17.0.6 hooks: - id: clang-format-metal
-
Install the pre-commit hook into your git repository:
pre-commit install
Once installed, the clang-format-metal
hook will automatically format .cpp
, .h
, .hpp
, and .metal
files each time you commit changes. To manually trigger formatting on all files without committing, you can run:
pre-commit run --all-files
This hook uses clang-format
with the -i
flag to format files in place. If you have specific clang-format
style preferences, ensure you have a .clang-format
configuration file in your repository's root or in an appropriate parent directory.
- clang-format not found: Ensure that
clang-format
is correctly installed and available in your system's PATH. You might need to specify the path toclang-format
in theentry
field of the.pre-commit-hooks.yaml
file if it's installed in a non-standard location. - Pre-commit hook not running: Make sure you've run
pre-commit install
in your repository to set up the hooks.
Contributions to improve clang-format-metal
are welcome! Please feel free to open issues or pull requests on our GitHub repository.