Skip to content

Commit bc50e72

Browse files
committed
clang format
1 parent 690ba92 commit bc50e72

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed

.clang-format

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
#Language: Cpp
3+
BasedOnStyle: LLVM
4+
AccessModifierOffset: -4
5+
#AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Left
9+
AlignOperands: false
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AllowShortBlocksOnASingleLine: Empty
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: All
15+
AllowShortIfStatementsOnASingleLine: WithoutElse
16+
AllowShortLoopsOnASingleLine: false
17+
AllowShortEnumsOnASingleLine: true
18+
AlwaysBreakAfterDefinitionReturnType: None
19+
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakBeforeMultilineStrings: false
21+
AlwaysBreakTemplateDeclarations: MultiLine
22+
BinPackArguments: true
23+
BinPackParameters: true
24+
BreakBeforeBraces: Custom
25+
BraceWrapping:
26+
AfterClass: true
27+
AfterControlStatement: Always
28+
AfterEnum: true
29+
AfterFunction: true
30+
AfterNamespace: true
31+
AfterObjCDeclaration: true
32+
AfterStruct: true
33+
AfterUnion: true
34+
AfterExternBlock: true
35+
BeforeCatch: true
36+
BeforeElse: true
37+
IndentBraces: false
38+
SplitEmptyFunction: false
39+
SplitEmptyRecord: false
40+
SplitEmptyNamespace: false
41+
BreakBeforeBinaryOperators: None
42+
ObjCSpaceBeforeProtocolList: false
43+
ObjCSpaceAfterProperty: true
44+
ObjCBlockIndentWidth: 4
45+
ObjCBreakBeforeNestedBlockParam: false
46+
BreakInheritanceList: AfterColon
47+
BreakBeforeTernaryOperators: false
48+
BreakConstructorInitializers: AfterColon
49+
BreakAfterJavaFieldAnnotations: true
50+
BreakStringLiterals: false
51+
ColumnLimit: 0
52+
CommentPragmas: '^ IWYU pragma:'
53+
CompactNamespaces: true
54+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
55+
ConstructorInitializerIndentWidth: 4
56+
ContinuationIndentWidth: 4
57+
Cpp11BracedListStyle: false
58+
DerivePointerAlignment: false
59+
DisableFormat: false
60+
ExperimentalAutoDetectBinPacking: false
61+
FixNamespaceComments: true
62+
ForEachMacros:
63+
- foreach
64+
- Q_FOREACH
65+
- BOOST_FOREACH
66+
IncludeBlocks: Regroup
67+
IncludeCategories:
68+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
69+
Priority: 2
70+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
71+
Priority: 3
72+
- Regex: '.*'
73+
Priority: 1
74+
#IncludeIsMainRegex: '(Test)?$'
75+
IndentCaseLabels: false
76+
IndentPPDirectives: None
77+
IndentWidth: 4
78+
IndentWrappedFunctionNames: true
79+
JavaScriptQuotes: Leave
80+
JavaScriptWrapImports: true
81+
KeepEmptyLinesAtTheStartOfBlocks: false
82+
#MacroBlockBegin: ''
83+
#MacroBlockEnd: ''
84+
MaxEmptyLinesToKeep: 1
85+
NamespaceIndentation: None
86+
IndentExternBlock: NoIndent
87+
PenaltyBreakAssignment: 4
88+
PenaltyBreakBeforeFirstCallParameter: 19
89+
PenaltyBreakComment: 300
90+
PenaltyBreakFirstLessLess: 120
91+
PenaltyBreakString: 1000
92+
PenaltyBreakTemplateDeclaration: 10
93+
PenaltyExcessCharacter: 1000000
94+
PenaltyReturnTypeOnItsOwnLine: 60
95+
PointerAlignment: Left
96+
ReflowComments: true
97+
SortIncludes: true
98+
SortUsingDeclarations: true
99+
SpaceAfterCStyleCast: false
100+
SpaceAfterTemplateKeyword: true
101+
SpaceBeforeAssignmentOperators: true
102+
SpaceBeforeCpp11BracedList: false
103+
SpaceBeforeCtorInitializerColon: true
104+
SpaceBeforeInheritanceColon: true
105+
SpaceBeforeParens: ControlStatements
106+
SpaceBeforeRangeBasedForLoopColon: true
107+
SpaceInEmptyParentheses: false
108+
SpacesBeforeTrailingComments: 1
109+
SpacesInAngles: false
110+
SpacesInContainerLiterals: true
111+
SpacesInCStyleCastParentheses: false
112+
SpacesInParentheses: false
113+
SpacesInSquareBrackets: false
114+
Standard: c++17
115+
StatementMacros:
116+
- Q_UNUSED
117+
- QT_REQUIRE_VERSION
118+
TabWidth: 4
119+
UseTab: Never
120+
---
121+
Language: Java
122+
DisableFormat: true
123+
---
124+
Language: TableGen
125+
DisableFormat: true
126+
---
127+
Language: TextProto
128+
DisableFormat: true
129+
---
130+
Language: CSharp
131+
DisableFormat: true
132+
---
133+
Language: Proto
134+
DisableFormat: true
135+
---
136+
Language: JavaScript
137+
DisableFormat: true
138+
...
139+

utils/format.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "$0")"
4+
5+
THIS_DIR="$(pwd)"
6+
cd ..
7+
8+
REPO_DIR="$(pwd)"
9+
10+
if ! [ -x "$(command -v clang-format)" ]; then
11+
echo 'clang-format is not installed.' >&2
12+
exit 1
13+
fi
14+
CF_VER=$(clang-format --version | sed -E "s/([^0-9]*)([0-9]+)\.(.*)/\2/")
15+
if (($CF_VER < 11)); then
16+
echo '[ERROR] clang-format version at least 11, please run [brew update && brew upgrade clang-format]'
17+
exit 1
18+
fi
19+
20+
if [[ "$1" == "--only-changed" ]]; then
21+
# 仅修改当前改变了的文件
22+
23+
declare -a CHANGED_FILES=()
24+
25+
while IFS=$'\n' read -r -a line; do
26+
echo "Find cached file: $line"
27+
CHANGED_FILES+=("$line")
28+
done < <(git diff --cached --name-only | grep -E '(.*)\.(h|hpp|cpp|m|mm)$' | grep -ivE "\.(vert|frag|sl)\..*\.(h|cpp)$")
29+
30+
while IFS=$'\n' read -r -a line; do
31+
echo "Find changed file: $line"
32+
CHANGED_FILES+=("$line")
33+
done < <(git diff --name-only | grep -E '(.*)\.(h|hpp|cpp|m|mm)$' | grep -ivE "\.(vert|frag|sl)\..*\.(h|cpp)$")
34+
35+
declare -a UNIQUE_CHANGED_FILES=()
36+
37+
if [[ "${#CHANGED_FILES[@]}" -ne 0 ]]; then
38+
while IFS=$'\n' read -r -a line; do
39+
UNIQUE_CHANGED_FILES+=("$line")
40+
echo "Processing file $line"
41+
clang-format -i --style=file $line
42+
done < <(printf "%s\n" ${CHANGED_FILES[@]} | sort | uniq)
43+
fi
44+
45+
echo "Total changed files: ${#UNIQUE_CHANGED_FILES[@]}"
46+
else
47+
cd "$REPO_DIR"
48+
subDir="library/src/main/jni"
49+
findDir=(cge interface custom)
50+
for name in ${findDir[@]}; do
51+
find -E "$subDir/$name" -type f -regex '(.*)\.(h|hpp|cpp|mm)$' | grep -ivE "\.(vert|frag|sl)\..*\.(h|cpp)$" | xargs clang-format -i --style=file
52+
done
53+
fi

0 commit comments

Comments
 (0)