├── setup.py ├── .pre-commit-hooks.yaml ├── LICENSE └── README.md /setup.py: -------------------------------------------------------------------------------- 1 | # Dummy setup.py to install cpplint properly. 2 | try: 3 | from setuptools import setup 4 | except ImportError: 5 | raise ImportError( 6 | "'setuptools' is required but not installed. To install it, " 7 | "follow the instructions at " 8 | "https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py" 9 | ) 10 | 11 | install_req = ["cpplint"] 12 | 13 | setup( 14 | name="dummy-cpplint-setup", 15 | version="0", 16 | author="Ben Morcos", 17 | license="MIT", 18 | description="Dummy setup for cpp pre-commit hooks", 19 | install_requires=install_req, 20 | ) 21 | -------------------------------------------------------------------------------- /.pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | - id: clang-format 2 | name: clang-format 3 | description: Format C code using clang-format. 4 | language: system 5 | files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ 6 | entry: clang-format -i 7 | args: ["-style=Google"] 8 | - id: cpplint 9 | name: cpplint 10 | description: Check style of C code using cpplint. 11 | language: python 12 | files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ 13 | entry: cpplint 14 | args: ["--verbose=3"] 15 | - id: cppcheck 16 | name: cppcheck 17 | description: Check correctness of C code using cppcheck. 18 | language: system 19 | files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ 20 | entry: cppcheck --error-exitcode=1 21 | args: ["--enable=warning"] 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ben Morcos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pre-commit hooks for cpp tools 2 | 3 | This provides [pre-commit](https://pre-commit.com/) hooks for 4 | [clang-format](https://clang.llvm.org/docs/ClangFormat.html), 5 | [cpplint](https://github.com/cpplint/cpplint), and 6 | [cppcheck](http://cppcheck.sourceforge.net/). 7 | 8 | ## Usage 9 | 10 | To use these hooks, simply place the following in you `.pre-commit-config.yaml` 11 | (more details below): 12 | 13 | ```yaml 14 | repos: 15 | - repo: https://github.com/bmorcos/pre-commit-hooks-cpp 16 | rev: master 17 | hooks: 18 | - id: clang-format 19 | - id: cpplint 20 | - id: cppcheck 21 | ``` 22 | 23 | ## clang-format 24 | 25 | This requires clang-format to be installed, e.g. `sudo apt install 26 | clang-format`. The default setup uses the Google style guide and will format all 27 | C/C++ files and headers found in the repo, however other arguments and 28 | particular files can specified. 29 | 30 | ```yaml 31 | - repo: https://github.com/bmorcos/pre-commit-hooks-cpp 32 | rev: master 33 | hooks: 34 | - id: clang-format 35 | # args: [--option1, -option2=abc] 36 | # files: my_file.cpp|my_other_file.cpp 37 | 38 | ``` 39 | 40 | ## cpplint 41 | 42 | This requires cpplint to be installed, e.g. `pip install cpplint`. The default 43 | setup uses the `--verbose=3` flag and will check all C/C++ files and headers 44 | found in the repo, however other arguments and particular files can specified. 45 | 46 | ```yaml 47 | - repo: https://github.com/bmorcos/pre-commit-hooks-cpp 48 | rev: master 49 | hooks: 50 | - id: cpplint 51 | # args: [--option1, -option2=abc] 52 | # files: my_file.cpp|my_other_file.cpp 53 | 54 | ``` 55 | 56 | ## cppcheck 57 | 58 | This requires cppcheck to be installed, e.g. `sudo apt install cppcheck`. The 59 | default setup enables warnings to be displayed and will check all C/C++ files 60 | and headers found in the repo, however other arguments and particular files can 61 | specified. 62 | 63 | ```yaml 64 | - repo: https://github.com/bmorcos/pre-commit-hooks-cpp 65 | rev: master 66 | hooks: 67 | - id: cppcheck 68 | # args: [--option1, -option2=abc] 69 | # files: my_file.cpp|my_other_file.cpp 70 | 71 | ``` 72 | --------------------------------------------------------------------------------