Skip to content
File

Blob: .clang-format

3.2 KB
1Language: Cpp
2Standard: c++20
3ColumnLimit: 100
4 
5WhitespaceSensitiveMacros:
6 # clang format doesn't understand TypeScript, so make sure it doesn't mangle
7 # overrides and additional definitions
8 - JSG_TS_OVERRIDE
9 - JSG_TS_DEFINE
10 - JSG_STRUCT_TS_OVERRIDE
11 - JSG_STRUCT_TS_DEFINE
12AllowShortFunctionsOnASingleLine: Empty
13 
14SortIncludes: true
15IncludeBlocks: Regroup
16IncludeCategories:
17 # c++ system headers
18 - Regex: <[a-zA-Z0-9_]+>
19 Priority: 5
20 # kj/capnp headers
21 - Regex: <(kj|capnp)/.+>
22 Priority: 4
23 # workerd headers
24 - Regex: <workerd/.+>
25 Priority: 2
26 # 3rd party headers
27 - Regex: <.+>
28 Priority: 3
29 # local headers
30 - Regex: '".*"'
31 Priority: 1
32 
33AllowShortIfStatementsOnASingleLine: true
34AllowShortLoopsOnASingleLine: true
35AllowShortBlocksOnASingleLine: Empty
36 
37IndentWidth: 2
38IndentCaseBlocks: false
39IndentCaseLabels: true
40PointerAlignment: Left
41DerivePointerAlignment: true
42 
43# Move public and private in by a half-indentation. This makes
44# diffs and Github code reviews more readable by letting you
45# see which class the diff snippet is part of.
46AccessModifierOffset: -1
47 
48# Really "Attach" but empty braces aren't split.
49BreakBeforeBraces: Custom
50BraceWrapping:
51 AfterCaseLabel: false
52 AfterClass: false
53 AfterControlStatement: Never
54 AfterEnum: false
55 AfterFunction: false
56 AfterNamespace: false
57 AfterObjCDeclaration: false
58 AfterStruct: false
59 AfterUnion: false
60 AfterExternBlock: false
61 BeforeCatch: false
62 BeforeElse: false
63 BeforeLambdaBody: false
64 BeforeWhile: false
65 IndentBraces: false
66 SplitEmptyFunction: false
67 SplitEmptyRecord: false
68 SplitEmptyNamespace: false
69 
70Cpp11BracedListStyle: true
71 
72AlignAfterOpenBracket: DontAlign
73AlignOperands: DontAlign
74AlignTrailingComments:
75 Kind: Always
76 OverEmptyLines: 0
77AlwaysBreakAfterReturnType: None
78AlwaysBreakTemplateDeclarations: Yes
79BreakStringLiterals: false
80BinPackArguments: true
81BinPackParameters: false
82BracedInitializerIndentWidth: 2
83BreakInheritanceList: BeforeColon
84ContinuationIndentWidth: 4
85IfMacros:
86 [
87 "KJ_SWITCH_ONEOF",
88 "KJ_CASE_ONEOF",
89 "KJ_IF_MAYBE",
90 "KJ_IF_SOME",
91 "CFJS_RESOURCE_TYPE",
92 ]
93LambdaBodyIndentation: OuterScope
94Macros:
95 - "KJ_MAP(x,y)=[y](auto x)"
96 - "JSG_VISITABLE_LAMBDA(x,y,z)=[x,y](z)"
97 # The WhitespaceSensitiveMacros solution is flaky, adding the following ensures no formatting:
98 - "JSG_TS_OVERRIDE(x)=enum class"
99 - "JSG_TS_DEFINE(x)=enum class"
100 - "JSG_STRUCT_TS_OVERRIDE(x)=enum class"
101 - "JSG_STRUCT_TS_DEFINE(x)=enum class"
102PenaltyReturnTypeOnItsOwnLine: 1000
103PackConstructorInitializers: CurrentLine
104ReflowComments: false
105SpaceBeforeCtorInitializerColon: false
106SpaceBeforeInheritanceColon: false
107SpaceBeforeParens: ControlStatementsExceptControlMacros
108SpaceBeforeRangeBasedForLoopColon: false
109SpaceBeforeCpp11BracedList: false
110SpacesBeforeTrailingComments: 2
111---
112# Some files with embedded typescript are incorrectly recognized by clang-format as Objective-C
113# This is because the C/C++ macro expansion step happens after the language recognition step, so
114# when trying to parse the file, the c++ parser fails with incorrect syntax and a fallback to
115# the Objective-C parser is used.
116# This is a workaround to hide the warning.
117# TODO: Remove this once we have a better solution.
118Language: ObjC
119DisableFormat: true