-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit and clang-format configuration and fix all issues (#173)
- Loading branch information
Showing
27 changed files
with
912 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
Language: Cpp | ||
# BasedOnStyle: LLVM | ||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: Align | ||
# AlignConsecutiveAssignments: true | ||
# AlignConsecutiveDeclarations: true | ||
AlignEscapedNewlines: Right | ||
AlignOperands: false | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: Never | ||
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: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Custom | ||
BreakBeforeInheritanceComma: false | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: AfterColon | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 120 | ||
CommentPragmas: '^ IWYU pragma:' | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
FixNamespaceComments: true | ||
ForEachMacros: | ||
- foreach | ||
- Q_FOREACH | ||
- BOOST_FOREACH | ||
IncludeBlocks: Preserve | ||
IncludeCategories: | ||
- Regex: '^(<|"(gtest|gmock|isl|json)/)' | ||
Priority: 4 | ||
- Regex: '.*' | ||
Priority: 3 | ||
IncludeIsMainRegex: '(Test)?$' | ||
IndentCaseLabels: false | ||
IndentPPDirectives: None | ||
IndentWidth: 2 | ||
IndentWrappedFunctionNames: false | ||
JavaScriptQuotes: Leave | ||
JavaScriptWrapImports: true | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: Inner | ||
PenaltyBreakAssignment: 2 | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 60 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyBreakTemplateDeclaration: 10 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Left | ||
ReflowComments: true | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeCpp11BracedList: false | ||
SpaceBeforeCtorInitializerColon: true | ||
SpaceBeforeInheritanceColon: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceBeforeRangeBasedForLoopColon: true | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: c++17 | ||
TabWidth: 8 | ||
UseTab: Never | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Thin wrapper around clang-format for easier to parse output from the | ||
# pre-commit hook. | ||
# | ||
# Needs to work with multiple input files as pre-commit passes multiple files to | ||
# the "executables" | ||
|
||
# Make sure that diff is actually recent enough (diffutils >= 3.4) to support | ||
# colored output | ||
COLOR_OUTPUT=$(diff --color=always <(echo) <(echo) > /dev/null 2>&1 && echo "--color=always") | ||
|
||
success=0 | ||
for file in ${@}; do | ||
if ! $(clang-format --style=file --Werror --dry-run ${file} > /dev/null 2>&1); then | ||
echo "Necessary changes for: '${file}' (run 'clang-format --style=file -i ${file}' to fix it)" | ||
diff ${COLOR_OUTPUT} -u ${file} <(clang-format --style=file ${file}) | tail -n +3 | ||
success=1 | ||
fi | ||
done | ||
exit ${success} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: pre-commit | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: cvmfs-contrib/github-action-cvmfs@v2 | ||
- uses: aidasoft/run-lcg-view@v3 | ||
with: | ||
release-platform: LCG_99/x86_64-centos7-clang10-opt | ||
run: | | ||
STARTDIR=$(pwd) | ||
echo "::group::Build podio" | ||
echo "Building podio @"$(git log -1 --format=%H) | ||
git clone --depth 1 https://github.com/AIDASoft/podio | ||
cd podio | ||
mkdir build install | ||
cd build | ||
cmake .. -DCMAKE_CXX_STANDARD=17 \ | ||
-DENABLE_SIO=ON \ | ||
-DBUILD_TESTING=OFF \ | ||
-DCMAKE_INSTALL_PREFIX=$(pwd)/../install \ | ||
-G Ninja | ||
ninja -k0 | ||
ninja install | ||
cd .. | ||
export ROOT_INCLUDE_PATH=$(pwd)/install/include:$ROOT_INCLUDE_PATH:$CPATH | ||
unset CPATH | ||
export CMAKE_PREFIX_PATH=$(pwd)/install:$CMAKE_PREFIX_PATH | ||
export LD_LIBRARY_PATH=$(pwd)/install/lib:$(pwd)/install/lib64:$LD_LIBRARY_PATH | ||
echo "::endgroup::" | ||
echo "::group::Run pre-commit" | ||
cd $STARTDIR | ||
export PYTHONPATH=$(python -m site --user-site):$PYTHONPATH | ||
export PATH=/root/.local/bin:$PATH | ||
pip install argparse --user | ||
pip install pre-commit --user | ||
mkdir build | ||
cd build | ||
cmake .. -DENABLE_SIO=ON \ | ||
-DCMAKE_CXX_STANDARD=17 \ | ||
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror "\ | ||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
-DUSE_EXTERNAL_CATCH2=OFF | ||
ln -s $(pwd)/compile_commands.json ../ | ||
cd .. | ||
pre-commit run --show-diff-on-failure \ | ||
--color=always \ | ||
--all-files | ||
echo "::endgroup::" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.4.0 | ||
hooks: | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
exclude: (doc/ReleaseNotes.md) | ||
- repo: local | ||
hooks: | ||
- id: clang-format | ||
name: clang-format | ||
entry: .github/scripts/clang-format-hook | ||
exclude: (edm4hep/(edm4hep|src)/.*(h|cc)$|EDM4HEPVersion.h) | ||
types: [c++] | ||
language: system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.