Skip to content

Commit 5a0c99a

Browse files
committed
clang-format: Add include sorting directives
Let's make sure clang-format sorts includes according to our style guide.
1 parent cf0f741 commit 5a0c99a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

.clang-format

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,34 @@ ForEachMacros:
107107
- STRV_FOREACH
108108
- STRV_FOREACH_BACKWARDS
109109
- STRV_FOREACH_PAIR
110+
IncludeBlocks: Regroup
111+
IncludeCategories:
112+
# To start a new block, bump Priority to max(Priority, SortPriority) + 1.
113+
# To sort lower within the same block, bump SortPriority to max(Priority, SortPriority) + 1.
114+
# "vmlinux.h" must always be included first in BPF programs before anything else.
115+
- Regex: '^"vmlinux.h"$'
116+
Priority: 1
117+
# <net/if.h>, <netinet/in.h> and <sys/mount.h> must be included before any <linux/*.h>.
118+
- Regex: '^<net/if\.h>$'
119+
Priority: 2
120+
- Regex: '^<netinet/in\.h>$'
121+
Priority: 2
122+
- Regex: '^<sys/mount\.h>$'
123+
Priority: 2
124+
# <linux/bpf.h> and <linux/types.h> should be included before any <bpf/*.h> headers.
125+
- Regex: '^<linux/(bpf|types)\.h>$'
126+
Priority: 2
127+
- Regex: '^<.*\.h>$'
128+
Priority: 2
129+
SortPriority: 3
130+
- Regex: '^"sd-.*\.h"$'
131+
Priority: 4
132+
- Regex: '^"audit_type-to-name.h"$'
133+
Priority: 6
134+
- Regex: '.*'
135+
Priority: 5
136+
# Make sure the "main header" is not treated any differently than other headers.
137+
IncludeIsMainRegex: '^$'
110138
IndentPPDirectives: AfterHash
111139
IndentWidth: 8
112140
IndentWrappedFunctionNames: true

0 commit comments

Comments
 (0)