Git pre-commit hooks for C/C++.
Add the following code to your .pre-commit-config.yaml
- repo: https://github.com/igankevich/pre-commit-cpp
rev: 0.5.0
hooks:
- id: normalise
args: ['--tab-width=4']
- id: header-guard
args: ['--only-missing', '--add-vim-filetype']
- id: normalise-opencl
- id: normalise-cpp
args: ['--src=src', '--top=sys/types.h']
normalise
— normalise white space in C/C++ files:- change encoding to UTF-8 using chardet library
- replace tabs at the beginning of the line with spaces
- replace white space at the end of the line with a newline character
- remove empty lines from the beginning and the end of the file
header-guard
— add/update header guard in C/C++ headers.normalise-cpp
— fix include paths in C/C++ files:- replace relative include paths with the paths relative to source directory
- sort headers excluding the ones that should always be on the top (e.g.
sys/types.h
)
normalise-opencl
— remove leading underscores from OpenCL keywords (e.g.kernel
instead of__kernel
. Currently this is pure regular expression substitution.
Public domain.