Skip to content

Commit cdffa24

Browse files
mfepMathiasMagnus
authored andcommitted
Added formatting
1 parent 4785b6d commit cdffa24

2 files changed

Lines changed: 178 additions & 0 deletions

File tree

.clang-format

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Right
8+
AlignOperands: false
9+
AlignTrailingComments: false
10+
AllowAllArgumentsOnNextLine: true
11+
AllowAllConstructorInitializersOnNextLine: true
12+
AllowAllParametersOfDeclarationOnNextLine: true
13+
AllowShortBlocksOnASingleLine: false
14+
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortFunctionsOnASingleLine: All
16+
AllowShortLambdasOnASingleLine: All
17+
AllowShortIfStatementsOnASingleLine: WithoutElse
18+
AllowShortLoopsOnASingleLine: true
19+
AlwaysBreakAfterDefinitionReturnType: None
20+
AlwaysBreakAfterReturnType: None
21+
AlwaysBreakBeforeMultilineStrings: false
22+
AlwaysBreakTemplateDeclarations: MultiLine
23+
BinPackArguments: true
24+
BinPackParameters: true
25+
BraceWrapping:
26+
AfterCaseLabel: false
27+
AfterClass: false
28+
AfterControlStatement: true
29+
AfterEnum: true
30+
AfterFunction: true
31+
AfterNamespace: false
32+
AfterObjCDeclaration: false
33+
AfterStruct: true
34+
AfterUnion: false
35+
AfterExternBlock: false
36+
BeforeCatch: false
37+
BeforeElse: true
38+
IndentBraces: false
39+
SplitEmptyFunction: false
40+
SplitEmptyRecord: true
41+
SplitEmptyNamespace: true
42+
BreakBeforeBinaryOperators: NonAssignment
43+
BreakBeforeBraces: Custom
44+
BreakBeforeInheritanceComma: false
45+
BreakInheritanceList: BeforeColon
46+
BreakBeforeTernaryOperators: true
47+
BreakConstructorInitializersBeforeComma: false
48+
BreakConstructorInitializers: BeforeColon
49+
BreakAfterJavaFieldAnnotations: false
50+
BreakStringLiterals: true
51+
ColumnLimit: 80
52+
CommentPragmas: '^ IWYU pragma:'
53+
CompactNamespaces: false
54+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
55+
ConstructorInitializerIndentWidth: 4
56+
ContinuationIndentWidth: 4
57+
Cpp11BracedListStyle: false
58+
DerivePointerAlignment: true
59+
DisableFormat: false
60+
ExperimentalAutoDetectBinPacking: false
61+
FixNamespaceComments: false
62+
ForEachMacros:
63+
- foreach
64+
- Q_FOREACH
65+
- BOOST_FOREACH
66+
IncludeBlocks: Preserve
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: true
76+
IndentPPDirectives: None
77+
IndentWidth: 4
78+
IndentWrappedFunctionNames: false
79+
JavaScriptQuotes: Leave
80+
JavaScriptWrapImports: true
81+
KeepEmptyLinesAtTheStartOfBlocks: true
82+
MacroBlockBegin: ''
83+
MacroBlockEnd: ''
84+
MaxEmptyLinesToKeep: 2
85+
NamespaceIndentation: Inner
86+
ObjCBinPackProtocolList: Auto
87+
ObjCBlockIndentWidth: 4
88+
ObjCSpaceAfterProperty: true
89+
ObjCSpaceBeforeProtocolList: true
90+
PenaltyBreakAssignment: 2
91+
PenaltyBreakBeforeFirstCallParameter: 19
92+
PenaltyBreakComment: 300
93+
PenaltyBreakFirstLessLess: 120
94+
PenaltyBreakString: 1000
95+
PenaltyBreakTemplateDeclaration: 10
96+
PenaltyExcessCharacter: 1000000
97+
PenaltyReturnTypeOnItsOwnLine: 60
98+
PointerAlignment: Left
99+
ReflowComments: true
100+
SortIncludes: false
101+
SortUsingDeclarations: true
102+
SpaceAfterCStyleCast: false
103+
SpaceAfterLogicalNot: false
104+
SpaceAfterTemplateKeyword: true
105+
SpaceBeforeAssignmentOperators: true
106+
SpaceBeforeCpp11BracedList: false
107+
SpaceBeforeCtorInitializerColon: false
108+
SpaceBeforeInheritanceColon: true
109+
SpaceBeforeParens: ControlStatements
110+
SpaceBeforeRangeBasedForLoopColon: true
111+
SpaceInEmptyParentheses: false
112+
SpacesBeforeTrailingComments: 1
113+
SpacesInAngles: false
114+
SpacesInContainerLiterals: true
115+
SpacesInCStyleCastParentheses: false
116+
SpacesInParentheses: false
117+
SpacesInSquareBrackets: false
118+
Standard: Cpp11
119+
StatementMacros:
120+
- Q_UNUSED
121+
- QT_REQUIRE_VERSION
122+
TabWidth: 4
123+
UseTab: Never

scripts/check-format.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
SOURCE_COMMIT="$1"
4+
if [ "$#" -gt 0 ]; then
5+
shift
6+
fi
7+
8+
# If no source commit is given target the default branch
9+
if [ "x$SOURCE_COMMIT" = "x" ]; then
10+
# If remote is not set use the remote of the current branch or fallback to "origin"
11+
if [ "x$REMOTE" = "x" ]; then
12+
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
13+
REMOTE="$(git config --local --get "branch.$BRANCH.remote" || echo 'origin')"
14+
fi
15+
SOURCE_COMMIT="remotes/$REMOTE/HEAD"
16+
fi
17+
18+
# Force colored diff output
19+
DIFF_COLOR_SAVED="$(git config --local --get color.diff)"
20+
if [ "x$DIFF_COLOR_SAVED" != "x" ]; then
21+
git config --local --replace-all "color.diff" "always"
22+
else
23+
git config --local --add "color.diff" "always"
24+
fi
25+
26+
scratch="$(mktemp -t check-format.XXXXXXXXXX)"
27+
finish () {
28+
# Remove temporary file
29+
rm -rf "$scratch"
30+
# Restore setting
31+
if [ "x$DIFF_COLOR_SAVED" != "x" ]; then
32+
git config --local --replace-all "color.diff" "$DIFF_COLOR_SAVED"
33+
else
34+
git config --local --unset "color.diff"
35+
fi
36+
}
37+
# The trap will be invoked whenever the script exits, even due to a signal, this is a bash only
38+
# feature
39+
trap finish EXIT
40+
41+
GIT_CLANG_FORMAT="${GIT_CLANG_FORMAT:-git-clang-format}"
42+
"$GIT_CLANG_FORMAT" --style=file --extensions=cc,cp,cpp,c++,cxx,cu,cuh,hh,hpp,hxx,hip,vert,frag --diff "$@" "$SOURCE_COMMIT" > "$scratch"
43+
44+
# Check for no-ops
45+
grep '^no modified files to format$\|^clang-format did not modify any files$' \
46+
"$scratch" > /dev/null && exit 0
47+
48+
# Dump formatting diff and signal failure
49+
printf \
50+
"\033[31m==== FORMATTING VIOLATIONS DETECTED ====\033[0m
51+
run '\033[33m%s --style=file %s %s\033[0m' to apply these formating changes\n\n" \
52+
"$GIT_CLANG_FORMAT" "$*" "$SOURCE_COMMIT"
53+
54+
cat "$scratch"
55+
exit 1

0 commit comments

Comments
 (0)