Skip to content

Commit 7191ecf

Browse files
authoredOct 6, 2021
Customize clang-format coding styles based on Mozilla template (#770)
Customize clang-format coding styles for C source files based on Mozilla template. To check whether the C source codes are well formatted: ``` bash $ cd ${wamr-root} $ clang-format --Werror --dry-run --style=file path/to/file ``` To format the C source codes in place ``` bash $ cd ${wamr_root} $ clang-format -i --style=file path/to/file ``` Signed-off-by: Wenyong Huang <[email protected]>
1 parent 9ef37dd commit 7191ecf

File tree

3 files changed

+301
-124
lines changed

3 files changed

+301
-124
lines changed
 

‎.clang-format

+22-124
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# using [clang-formt-12 options](https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html)
12
RawStringFormats:
2-
- Language: Cpp
3+
- Language: Cpp
34
Delimiters:
45
- c
56
- C
@@ -13,35 +14,23 @@ RawStringFormats:
1314
- h
1415
- hpp
1516
CanonicalDelimiter: ''
16-
BasedOnStyle: google
17-
- Language: TextProto
18-
Delimiters:
19-
- pb
20-
- PB
21-
- proto
22-
- PROTO
23-
EnclosingFunctions:
24-
- EqualsProto
25-
- EquivToProto
26-
- PARSE_PARTIAL_TEXT_PROTO
27-
- PARSE_TEST_PROTO
28-
- PARSE_TEXT_PROTO
29-
- ParseTextOrDie
30-
- ParseTextProtoOrDie
31-
CanonicalDelimiter: ''
32-
BasedOnStyle: google
17+
BasedOnStyle: Mozilla
3318

3419
Language: Cpp
3520
BasedOnStyle: Mozilla
21+
# 6.1
3622
IndentWidth: 4
23+
ContinuationIndentWidth: 4
24+
# 6.2
25+
TabWidth: 4
26+
UseTab: Never
27+
# 6.3
28+
ColumnLimit: 80
29+
# 6.9
3730
AlignAfterOpenBracket: Align
38-
AllowAllArgumentsOnNextLine: false
39-
AlignConsecutiveMacros: true
40-
AllowShortBlocksOnASingleLine: true
41-
AlwaysBreakAfterReturnType: All
4231
BinPackArguments: true
43-
BinPackParameters: false
44-
BreakBeforeBinaryOperators: NonAssignment
32+
BinPackParameters: true
33+
# 6.10
4534
BreakBeforeBraces: Custom
4635
BraceWrapping:
4736
AfterCaseLabel: true
@@ -60,104 +49,13 @@ BraceWrapping:
6049
SplitEmptyFunction: true
6150
SplitEmptyRecord: false
6251
SplitEmptyNamespace: true
63-
ColumnLimit: 79
64-
ContinuationIndentWidth: 2
65-
DerivePointerAlignment: false
66-
IncludeBlocks: Regroup
67-
IncludeCategories:
68-
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
69-
Priority: 2
70-
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
71-
Priority: 1
72-
- Regex: ".*"
73-
Priority: 3
74-
IndentPPDirectives: None
75-
KeepEmptyLinesAtTheStartOfBlocks: false
76-
NamespaceIndentation: None
77-
PointerAlignment: Right
78-
ReflowComments: false
79-
SortIncludes: false
80-
Standard: Auto
81-
StatementMacros:
82-
- Q_UNUSED
83-
- QT_REQUIRE_VERSION
84-
85-
# AccessModifierOffset: -2
86-
# AlignConsecutiveAssignments: false
87-
# AlignConsecutiveDeclarations: false
88-
# AlignEscapedNewlines: Right
89-
# AlignOperands: true
90-
# AlignTrailingComments: true
91-
# AllowAllConstructorInitializersOnNextLine: true
92-
# AllowAllParametersOfDeclarationOnNextLine: false
93-
# AllowShortCaseLabelsOnASingleLine: false
94-
# AllowShortFunctionsOnASingleLine: Inline
95-
# AllowShortLambdasOnASingleLine: All
96-
# AllowShortIfStatementsOnASingleLine: Never
97-
# AllowShortLoopsOnASingleLine: false
98-
# AlwaysBreakAfterDefinitionReturnType: TopLevel
99-
# AlwaysBreakAfterReturnType: TopLevel
100-
# AlwaysBreakBeforeMultilineStrings: false
101-
# AlwaysBreakTemplateDeclarations: Yes
102-
# BreakBeforeInheritanceComma: false
103-
# BreakInheritanceList: BeforeComma
104-
# BreakBeforeTernaryOperators: true
105-
# BreakConstructorInitializersBeforeComma: false
106-
# BreakConstructorInitializers: BeforeComma
107-
# BreakAfterJavaFieldAnnotations: false
108-
# BreakStringLiterals: true
109-
# CommentPragmas: '^ IWYU pragma:'
110-
# CompactNamespaces: false
111-
# ConstructorInitializerAllOnOneLineOrOnePerLine: false
112-
# ConstructorInitializerIndentWidth: 2
113-
# Cpp11BracedListStyle: false
114-
# DisableFormat: false
115-
# ExperimentalAutoDetectBinPacking: false
116-
# FixNamespaceComments: false
117-
# ForEachMacros:
118-
# - foreach
119-
# - Q_FOREACH
120-
# - BOOST_FOREACH
121-
# IncludeIsMainRegex: '(Test)?$'
122-
# IndentCaseLabels: true
123-
# IndentWrappedFunctionNames: false
124-
# JavaScriptQuotes: Leave
125-
# JavaScriptWrapImports: true
126-
# KeepEmptyLinesAtTheStartOfBlocks: true
127-
# MacroBlockBegin: ''
128-
# MacroBlockEnd: ''
129-
# MaxEmptyLinesToKeep: 1
130-
# ObjCBinPackProtocolList: Auto
131-
# ObjCBlockIndentWidth: 2
132-
# ObjCSpaceAfterProperty: true
133-
# ObjCSpaceBeforeProtocolList: false
134-
# PenaltyBreakAssignment: 2
135-
# PenaltyBreakBeforeFirstCallParameter: 19
136-
# PenaltyBreakComment: 300
137-
# PenaltyBreakFirstLessLess: 120
138-
# PenaltyBreakString: 1000
139-
# PenaltyBreakTemplateDeclaration: 10
140-
# PenaltyExcessCharacter: 1000000
141-
# PenaltyReturnTypeOnItsOwnLine: 200
142-
# SortIncludes: true
143-
# SortUsingDeclarations: true
144-
# SpaceAfterCStyleCast: false
145-
# SpaceAfterLogicalNot: false
146-
# SpaceAfterTemplateKeyword: false
147-
# SpaceBeforeAssignmentOperators: true
148-
# SpaceBeforeCpp11BracedList: false
149-
# SpaceBeforeCtorInitializerColon: true
150-
# SpaceBeforeInheritanceColon: true
151-
# SpaceBeforeParens: ControlStatements
152-
# SpaceBeforeRangeBasedForLoopColon: true
153-
# SpaceInEmptyParentheses: false
154-
# SpacesBeforeTrailingComments: 1
155-
# SpacesInAngles: false
156-
# SpacesInContainerLiterals: true
157-
# SpacesInCStyleCastParentheses: false
158-
# SpacesInParentheses: false
159-
# SpacesInSquareBrackets: false
160-
# TabWidth: 4
161-
# UseTab: Never
162-
# ...
52+
# 6.27
53+
BreakBeforeBinaryOperators: NonAssignment
16354

55+
# additional
56+
AlignEscapedNewlines: Left
57+
AllowAllParametersOfDeclarationOnNextLine: false
58+
AllowAllArgumentsOnNextLine: false
59+
PointerAlignment: Right
60+
SpaceAroundPointerQualifiers: After
61+
SortIncludes: false

‎.clang-tidy

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html
2+
3+
Checks: '-*, readability-identifier-naming, clang-analyzer-core.*,'
4+
WarningsAsErrors: '-*'
5+
HeaderFilterRegex: ''
6+
FormatStyle: file
7+
InheritParentConfig: false
8+
AnalyzeTemporaryDtors: false
9+
User: wamr
10+
CheckOptions:
11+
- key: readability-identifier-naming.VariableCase
12+
value: lower_case
13+
- key: readability-identifier-naming.ParameterCase
14+
value: lower_case
15+
- key: readability-identifier-naming.MacroDefinitionCase
16+
value: UPPER_CASE

0 commit comments

Comments
 (0)
Please sign in to comment.