Skip to content

Commit 1987d89

Browse files
committed
format: add cmake-format to pre-commit
1 parent c2ef5b4 commit 1987d89

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

.cmake-format.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
parse:
2+
additional_commands:
3+
pybind11_add_module:
4+
flags:
5+
- THIN_LTO
6+
- MODULE
7+
- SHARED
8+
- NO_EXTRAS
9+
- EXCLUDE_FROM_ALL
10+
- SYSTEM
11+
12+
format:
13+
line_width: 99
14+
tab_size: 2
15+
16+
# If an argument group contains more than this many sub-groups
17+
# (parg or kwarg groups) then force it to a vertical layout.
18+
max_subgroups_hwrap: 2
19+
20+
# If a positional argument group contains more than this many
21+
# arguments, then force it to a vertical layout.
22+
max_pargs_hwrap: 6
23+
24+
# If a cmdline positional group consumes more than this many
25+
# lines without nesting, then invalidate the layout (and nest)
26+
max_rows_cmdline: 2
27+
separate_ctrl_name_with_space: false
28+
separate_fn_name_with_space: false
29+
dangle_parens: false
30+
31+
# If the trailing parenthesis must be 'dangled' on its on
32+
# 'line, then align it to this reference: `prefix`: the start'
33+
# 'of the statement, `prefix-indent`: the start of the'
34+
# 'statement, plus one indentation level, `child`: align to'
35+
# the column of the arguments
36+
dangle_align: prefix
37+
# If the statement spelling length (including space and
38+
# parenthesis) is smaller than this amount, then force reject
39+
# nested layouts.
40+
min_prefix_chars: 4
41+
42+
# If the statement spelling length (including space and
43+
# parenthesis) is larger than the tab width by more than this
44+
# amount, then force reject un-nested layouts.
45+
max_prefix_chars: 10
46+
47+
# If a candidate layout is wrapped horizontally but it exceeds
48+
# this many lines, then reject the layout.
49+
max_lines_hwrap: 2
50+
51+
line_ending: unix
52+
53+
# Format command names consistently as 'lower' or 'upper' case
54+
command_case: canonical
55+
56+
# Format keywords consistently as 'lower' or 'upper' case
57+
# unchanged is valid too
58+
keyword_case: 'upper'
59+
60+
# A list of command names which should always be wrapped
61+
always_wrap: []
62+
63+
# If true, the argument lists which are known to be sortable
64+
# will be sorted lexicographically
65+
enable_sort: true
66+
67+
# If true, the parsers may infer whether or not an argument
68+
# list is sortable (without annotation).
69+
autosort: false

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ repos:
2626
additional_dependencies: [flake8-bugbear, pep8-naming]
2727
exclude: ^(docs/.*|tools/.*)$
2828

29+
- repo: https://github.com/cheshirekow/cmake-format-precommit
30+
rev: v0.6.10
31+
hooks:
32+
- id: cmake-format
33+
additional_dependencies: [pyyaml]
34+
2935
- repo: local
3036
hooks:
3137
- id: check-style

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ endforeach()
217217
set(testdir ${CMAKE_CURRENT_SOURCE_DIR})
218218
foreach(target ${test_targets})
219219
set(test_files ${PYBIND11_TEST_FILES})
220-
if(NOT target STREQUAL "pybind11_tests")
220+
if(NOT "${target}" STREQUAL "pybind11_tests")
221221
set(test_files "")
222222
endif()
223223

0 commit comments

Comments
 (0)