Skip to content

Commit 86d2d6d

Browse files
committed
tools: initialize .clang-format with Google styles
- Initializes .clang-format - Add `make format` to Makefile
1 parent 2438877 commit 86d2d6d

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

.clang-format

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# # Defines the Google C++ style for automatic reformatting.
2+
# # http://clang.llvm.org/docs/ClangFormatStyleOptions.html
3+
AccessModifierOffset: -1
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Right
8+
AlignOperands: true
9+
AlignTrailingComments: false
10+
AllowAllParametersOfDeclarationOnNextLine: false
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: InlineOnly
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: true
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: false
19+
AlwaysBreakTemplateDeclarations: true
20+
BinPackArguments: false
21+
BinPackParameters: false
22+
BraceWrapping:
23+
AfterClass: false
24+
AfterControlStatement: false
25+
AfterEnum: false
26+
AfterFunction: false
27+
AfterNamespace: false
28+
AfterObjCDeclaration: false
29+
AfterStruct: false
30+
AfterUnion: false
31+
AfterExternBlock: false
32+
BeforeCatch: false
33+
BeforeElse: false
34+
IndentBraces: false
35+
SplitEmptyFunction: true
36+
SplitEmptyRecord: true
37+
SplitEmptyNamespace: true
38+
BreakBeforeBinaryOperators: None
39+
BreakBeforeBraces: Attach
40+
BreakBeforeInheritanceComma: false
41+
BreakBeforeTernaryOperators: false
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakConstructorInitializers: BeforeColon
44+
BreakAfterJavaFieldAnnotations: false
45+
BreakStringLiterals: true
46+
ColumnLimit: 79
47+
CommentPragmas: '^ IWYU pragma:'
48+
CompactNamespaces: false
49+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
50+
ConstructorInitializerIndentWidth: 4
51+
ContinuationIndentWidth: 4
52+
Cpp11BracedListStyle: true
53+
DerivePointerAlignment: true
54+
DisableFormat: false
55+
ExperimentalAutoDetectBinPacking: false
56+
FixNamespaceComments: true
57+
ForEachMacros:
58+
- foreach
59+
- Q_FOREACH
60+
- BOOST_FOREACH
61+
IncludeCategories:
62+
- Regex: '^<ext/.*\.h>'
63+
Priority: 2
64+
- Regex: '^<.*\.h>'
65+
Priority: 1
66+
- Regex: '^<.*'
67+
Priority: 2
68+
- Regex: '.*'
69+
Priority: 3
70+
IncludeIsMainRegex: '([-_](test|unittest))?$'
71+
IndentCaseLabels: true
72+
IndentPPDirectives: None
73+
IndentWidth: 2
74+
IndentWrappedFunctionNames: false
75+
JavaScriptQuotes: Leave
76+
JavaScriptWrapImports: true
77+
KeepEmptyLinesAtTheStartOfBlocks: false
78+
MacroBlockBegin: ''
79+
MacroBlockEnd: ''
80+
MaxEmptyLinesToKeep: 2
81+
NamespaceIndentation: None
82+
ObjCBlockIndentWidth: 2
83+
ObjCSpaceAfterProperty: false
84+
ObjCSpaceBeforeProtocolList: false
85+
PenaltyBreakAssignment: 10
86+
PenaltyBreakBeforeFirstCallParameter: 20
87+
PenaltyBreakComment: 300
88+
PenaltyBreakFirstLessLess: 120
89+
PenaltyBreakString: 1000
90+
PenaltyExcessCharacter: 1000000
91+
PenaltyReturnTypeOnItsOwnLine: 200
92+
PointerAlignment: Left
93+
ReflowComments: true
94+
SortIncludes: true
95+
SortUsingDeclarations: true
96+
SpaceAfterCStyleCast: false
97+
SpaceAfterTemplateKeyword: true
98+
SpaceBeforeAssignmentOperators: true
99+
SpaceBeforeParens: ControlStatements
100+
SpaceInEmptyParentheses: false
101+
SpacesBeforeTrailingComments: 2
102+
SpacesInAngles: false
103+
SpacesInContainerLiterals: true
104+
SpacesInCStyleCastParentheses: false
105+
SpacesInParentheses: false
106+
SpacesInSquareBrackets: false
107+
Standard: Auto
108+
TabWidth: 8
109+
UseTab: Never
110+
# ...
111+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
!.mailmap
1515
!.nycrc
1616
!.remarkrc
17+
!.clang-format
1718

1819
core
1920
vgcore.*

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,18 @@ bench: bench-net bench-http bench-fs bench-tls
949949

950950
bench-ci: bench
951951

952+
CLANG_FORMAT = $(NODE) ./node_modules/.bin/clang-format -style=file -i
953+
954+
format:
955+
mkdir -p node_modules
956+
if [ ! -d node_modules/clang-format ]; then \
957+
./node ./deps/npm install clang-format --no-save --no-package-lock; fi
958+
$(CLANG_FORMAT) --glob=src/**/*.cc
959+
$(CLANG_FORMAT) --glob=src/**/*.h
960+
# $(CLANG_FORMAT) --glob=test/**/*.cc
961+
# $(CLANG_FORMAT) --glob=test/**/*.c
962+
# $(CLANG_FORMAT) --glob=test/**/*.h
963+
952964
lint-md-clean:
953965
$(RM) -r tools/remark-cli/node_modules
954966
$(RM) -r tools/remark-preset-lint-node/node_modules

0 commit comments

Comments
 (0)