Skip to content

Commit a49dde1

Browse files
author
Linus Torvalds
committed
Add clang-format and clang-tidy configs
1 parent 452e6b5 commit a49dde1

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed

.clang-format

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
Language: C
3+
IndentWidth: 4
4+
ColumnLimit: 80
5+
MaxEmptyLinesToKeep: 1
6+
7+
# These are clang-format 13 features:
8+
LambdaBodyIndentation: Signature
9+
ReferenceAlignment: Left
10+
11+
# These are clang-format 14 features:
12+
QualifierAlignment: Custom
13+
QualifierOrder: ['static', 'inline', 'constexpr', 'type', 'const', 'volatile' ]
14+
AlignArrayOfStructures: Right
15+
SeparateDefinitionBlocks: Always
16+
17+
# These are clang-format 15 features:
18+
RequiresClausePosition: OwnLine
19+
InsertBraces: true
20+
IndentRequiresClause: true
21+
22+
# These are clang-format 16 features:
23+
BreakAfterAttributes: Always
24+
RequiresExpressionIndentation: Keyword
25+
BreakBeforeInlineASMColon: Always
26+
27+
# These are clang-format 17 features:
28+
29+
# ----------------------------------
30+
BraceWrapping:
31+
AfterEnum: false
32+
33+
AlignAfterOpenBracket: Align
34+
AlignConsecutiveAssignments: None
35+
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
36+
AlignConsecutiveDeclarations: None
37+
AlignEscapedNewlines: Left
38+
AlignOperands: Align
39+
AlignTrailingComments: true
40+
AllowAllArgumentsOnNextLine: true
41+
AllowAllConstructorInitializersOnNextLine: true
42+
AllowAllParametersOfDeclarationOnNextLine: true
43+
AllowShortEnumsOnASingleLine: false
44+
AllowShortBlocksOnASingleLine: Never
45+
AllowShortCaseLabelsOnASingleLine: false
46+
AllowShortFunctionsOnASingleLine: None
47+
AllowShortLambdasOnASingleLine: None
48+
AllowShortIfStatementsOnASingleLine: WithoutElse
49+
AllowShortLoopsOnASingleLine: false
50+
AlwaysBreakAfterDefinitionReturnType: None
51+
AlwaysBreakBeforeMultilineStrings: false
52+
AlwaysBreakTemplateDeclarations: Yes
53+
BinPackArguments: true
54+
BinPackParameters: true
55+
BreakBeforeBinaryOperators: None # This is broken until clang-format 14.
56+
BreakBeforeConceptDeclarations: true
57+
BreakBeforeBraces: Attach
58+
BreakBeforeInheritanceComma: false
59+
BreakInheritanceList: BeforeColon
60+
BreakBeforeTernaryOperators: true
61+
BreakConstructorInitializersBeforeComma: false
62+
BreakConstructorInitializers: BeforeColon
63+
BreakStringLiterals: true
64+
CompactNamespaces: false
65+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: false
68+
DerivePointerAlignment: false
69+
EmptyLineBeforeAccessModifier: Always
70+
ExperimentalAutoDetectBinPacking: false
71+
FixNamespaceComments: true
72+
SortIncludes: true
73+
IncludeBlocks: Regroup
74+
IncludeCategories:
75+
- Regex: '^<ext/.*\.hpp>'
76+
Priority: 2
77+
SortPriority: 0
78+
CaseSensitive: true
79+
- Regex: '^<.*\.hpp>'
80+
Priority: 1
81+
SortPriority: 0
82+
CaseSensitive: true
83+
- Regex: '^<.*\.tpp>'
84+
Priority: 1
85+
SortPriority: 0
86+
CaseSensitive: true
87+
- Regex: '^<.*'
88+
Priority: 2
89+
SortPriority: 0
90+
CaseSensitive: true
91+
- Regex: '.*'
92+
Priority: 3
93+
SortPriority: 0
94+
CaseSensitive: true
95+
IndentCaseLabels: true
96+
IndentCaseBlocks: true
97+
IndentGotoLabels: false
98+
IndentPPDirectives: None
99+
IndentExternBlock: AfterExternBlock
100+
IndentWrappedFunctionNames: false
101+
InsertTrailingCommas: None
102+
KeepEmptyLinesAtTheStartOfBlocks: false
103+
NamespaceIndentation: Inner
104+
PenaltyBreakAssignment: 2
105+
PenaltyBreakBeforeFirstCallParameter: 1
106+
PenaltyBreakComment: 300
107+
PenaltyBreakFirstLessLess: 120
108+
PenaltyBreakString: 1000
109+
PenaltyBreakTemplateDeclaration: 10
110+
PenaltyExcessCharacter: 1000000
111+
PenaltyReturnTypeOnItsOwnLine: 200
112+
PenaltyIndentedWhitespace: 0
113+
PointerAlignment: Left
114+
ReflowComments: true
115+
SortUsingDeclarations: true
116+
SpaceAfterCStyleCast: false
117+
SpaceAfterLogicalNot: false
118+
SpaceAfterTemplateKeyword: true
119+
SpaceBeforeAssignmentOperators: true
120+
SpaceBeforeCaseColon: false
121+
SpaceBeforeCpp11BracedList: false
122+
SpaceBeforeCtorInitializerColon: true
123+
SpaceBeforeInheritanceColon: true
124+
SpaceBeforeParens: ControlStatements
125+
SpaceAroundPointerQualifiers: Default
126+
SpaceBeforeRangeBasedForLoopColon: true
127+
SpaceInEmptyBlock: false
128+
SpaceInEmptyParentheses: false
129+
SpacesBeforeTrailingComments: 2
130+
SpacesInAngles: false
131+
SpacesInConditionalStatement: false
132+
SpacesInContainerLiterals: true
133+
SpacesInCStyleCastParentheses: false
134+
SpacesInParentheses: false
135+
SpacesInSquareBrackets: false
136+
SpaceBeforeSquareBrackets: false
137+
BitFieldColonSpacing: Both
138+
StatementMacros: ['defer']
139+
Standard: Auto
140+
UseCRLF: false
141+
UseTab: Never
142+
...

.clang-tidy

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
Checks: "bugprone-*,
3+
performance-*,
4+
modernize-*,
5+
readability-*,
6+
misc-*,
7+
# DISABLE SOME CHECKS:
8+
-bugprone-easily-swappable-parameters, # I'm on the fence about this.
9+
-bugprone-reserved-identifier, # libCat needs to make some of these.
10+
-performance-noexcept-move-constructor, # libCat doesn't have exceptions yet.
11+
-modernize-avoid-c-arrays, # They're needed in some low-level code.
12+
-modernize-use-auto, # I rather human judgement.
13+
-readability-magic-numbers, # I rather human judgement.
14+
-readability-identifier-length, # I rather human judgement.
15+
-readability-uppercase-literal-suffix, # I prefer lowercase.
16+
-readability-function-cognitive-complexity, # I don't trust this.
17+
-readability-convert-member-functions-to-static, # I rather human judgement.
18+
-readability-named-parameter, # I'm on the fence about this.
19+
-readability-function-cognitive-complexity, # I rather human judgement.
20+
-misc-non-private-member-variables-in-classes, # This seems very bad.
21+
-misc-unused-using-decls, # This isn't helpful for libraries.
22+
"
23+
24+
WarningsAsErrors: ''
25+
HeaderFilterRegex: ^src
26+
AnalyzeTemporaryDtors: false
27+
FormatStyle: file
28+
29+
CheckOptions:
30+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
31+
- { key: readability-identifier-naming.MemberCase, value: lower_case }
32+
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
33+
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
34+
- { key: readability-identifier-naming.StructCase, value: lower_case }
35+
- { key: readability-identifier-naming.ClassCase, value: lower_case }
36+
- { key: readability-identifier-naming.TypeAliasCase, value: lower_case }
37+
- { key: readability-identifier-naming.TypedefCase, value: lower_case }
38+
- { key: readability-identifier-naming.PointerParameterPrefix, value: p_ }
39+
- { key: readability-identifier-naming.LocalPointerPrefix, value: p_ }
40+
- { key: readability-identifier-naming.LocalConstantPointerPrefix, value: p_ }
41+
- { key: readability-identifier-naming.TemplateParameterIgnoredRegexp, value: '[A-Z]' }
42+
- { key: readability-identifier-naming.TypeAliasIgnoredRegexp, value: '[A-Z]' }
43+
- { key: readability-identifier-naming.TypedefIgnoredRegexp, value: '[A-Z]' }
44+
- { key: performance-unnecessary-value-param.AllowedTypes, value: string;span;io_vector }
45+
- { key: readability-operators-representation.BinaryOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^=' }
46+
...

0 commit comments

Comments
 (0)