-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce coding style #39
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
BasedOnStyle: LLVM | ||
IndentWidth: 4 | ||
--- | ||
Language: Cpp | ||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Right | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
AfterClass: false | ||
AfterControlStatement: false | ||
AfterEnum: false | ||
AfterFunction: false | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
AfterExternBlock: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Attach | ||
BreakBeforeInheritanceComma: false | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: BeforeColon | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 80 | ||
CommentPragmas: '^ IWYU pragma:' | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
FixNamespaceComments: true | ||
ForEachMacros: | ||
- foreach | ||
- Q_FOREACH | ||
- BOOST_FOREACH | ||
IncludeBlocks: Preserve | ||
IncludeCategories: | ||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | ||
Priority: 2 | ||
- Regex: '^(<|"(gtest|gmock|isl|json)/)' | ||
Priority: 3 | ||
- Regex: '.*' | ||
Priority: 1 | ||
IncludeIsMainRegex: '(Test)?$' | ||
IndentCaseLabels: false | ||
IndentPPDirectives: None | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
JavaScriptQuotes: Leave | ||
JavaScriptWrapImports: true | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 4 | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: true | ||
PenaltyBreakAssignment: 2 | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Right | ||
ReflowComments: true | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 8 | ||
UseTab: Never | ||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ matrix: | |
env: | ||
- OS_TYPE=doxygen | ||
addons: { apt: { packages: ["cmake", "graphviz"] } } | ||
- os: linux | ||
env: | ||
- OS_TYPE=clangformat | ||
addons: { apt: { packages: ["clang-format-6.0"], sources: ["llvm-toolchain-xenial-6.0"] } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curios: would this work? also, is ther a generic |
||
|
||
before_install: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
echo_red() { printf "\033[1;31m$*\033[m\n"; } | ||
echo_green() { printf "\033[1;32m$*\033[m\n"; } | ||
|
||
############################################################################ | ||
# Check if the file given as input has .h or .cpp extension | ||
############################################################################ | ||
is_source_file() { | ||
local file="$1" | ||
|
||
EXTENSIONS=".hpp .cpp" | ||
|
||
for extension in $EXTENSIONS; do | ||
[[ "${file: -2}" == "$extension" || "${file: -4}" == "$extension" ]] && return 0 | ||
done; | ||
|
||
return 1 | ||
} | ||
|
||
|
||
############################################################################ | ||
# Check if the files modified in the current commit / commit range respect | ||
# the coding style defined in the .clang-format file | ||
############################################################################ | ||
COMMIT_RANGE=$TRAVIS_COMMIT_RANGE | ||
|
||
if [ -z "$TRAVIS_PULL_REQUEST_SHA" ] | ||
then | ||
COMMIT_RANGE=HEAD~1 | ||
fi | ||
|
||
git diff --name-only --diff-filter=d $COMMIT_RANGE | while read -r file; do | ||
if is_source_file "$file" | ||
then | ||
/usr/bin/clang-format-6.0 -i "$file" | ||
fi | ||
done; | ||
|
||
git diff --exit-code || { | ||
echo_red "The code is not properly formatted!" | ||
exit 1 | ||
} | ||
|
||
echo_green "The code is properly formatted!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be annoying as if sorts the included headers alphabetically. You usually want more flexibility on order of the included files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also specify include categories, which will provide some general rules on how the included headers will be sorted.