@@ -176,10 +176,35 @@ name, pre-commit):
176176pre-commit install
177177```
178178
179+ ### Clang-Format
180+
181+ As of v2.6.2, pybind11 ships with a [ ` clang-format ` ] [ clang-format ]
182+ configuration file at the top level of the repo (the filename is
183+ ` .clang-format ` ). Currently, formatting is NOT applied automatically, but
184+ manually using ` clang-format ` for newly developed files is highly encouraged.
185+ To check if a file needs formatting:
186+
187+ ``` bash
188+ clang-format -style=file --dry-run some.cpp
189+ ```
190+
191+ The output will show things to be fixed, if any. To actually format the file:
192+
193+ ``` bash
194+ clang-format -style=file -i some.cpp
195+ ```
196+
197+ Note that the ` -style-file ` option searches the parent directories for the
198+ ` .clang-format ` file, i.e. the commands above can be run in any subdirectory
199+ of the pybind11 repo.
200+
179201### Clang-Tidy
180202
181- To run Clang tidy, the following recipe should work. Files will be modified in
182- place, so you can use git to monitor the changes.
203+ [ ` clang-tidy ` ] [ clang-tidy ] performs deeper static code analyses and is
204+ more complex to run, compared to ` clang-format ` , but support for ` clang-tidy `
205+ is built into the pybind11 CMake configuration. To run ` clang-tidy ` , the
206+ following recipe should work. Files will be modified in place, so you can
207+ use git to monitor the changes.
183208
184209``` bash
185210docker run --rm -v $PWD :/pybind11 -it silkeh/clang:10
@@ -198,7 +223,7 @@ cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-y
198223cmake --build build
199224```
200225
201- The report is sent to stderr; you can pip it into a file if you wish.
226+ The report is sent to stderr; you can pipe it into a file if you wish.
202227
203228### Build recipes
204229
@@ -325,6 +350,8 @@ if you really want to.
325350
326351
327352[ pre-commit ] : https://pre-commit.com
353+ [ clang-format ] : https://clang.llvm.org/docs/ClangFormat.html
354+ [ clang-tidy ] : https://clang.llvm.org/extra/clang-tidy/
328355[ pybind11.readthedocs.org ] : http://pybind11.readthedocs.org/en/latest
329356[ issue tracker ] : https://github.com/pybind/pybind11/issues
330357[ gitter ] : https://gitter.im/pybind/Lobby
0 commit comments