Skip to content

Commit f6442aa

Browse files
tmadlenervvolkl
andauthored
Add clang-format config and basic pre-commit workflow (#87)
* Extend .gitignore to LSP related tooling * Add .clang-format config from k4-project-template * Add pre-commit configuration * [pre-commit] Pre-commit whitespace fixes * [clang-format] Fix all clang-format issues Co-authored-by: Valentin Volkl <[email protected]>
1 parent e4b846e commit f6442aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+476
-393
lines changed

.clang-format

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: true
6+
AlignConsecutiveDeclarations: true
7+
AlignEscapedNewlinesLeft: true
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: true
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: true
19+
AlwaysBreakTemplateDeclarations: false
20+
BinPackArguments: true
21+
BinPackParameters: true
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+
BeforeCatch: false
32+
BeforeElse: false
33+
IndentBraces: false
34+
BreakBeforeBinaryOperators: None
35+
BreakBeforeBraces: Attach
36+
BreakBeforeTernaryOperators: true
37+
BreakConstructorInitializersBeforeComma: false
38+
BreakAfterJavaFieldAnnotations: false
39+
BreakStringLiterals: true
40+
ColumnLimit: 120
41+
CommentPragmas: '^ IWYU pragma:'
42+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
43+
ConstructorInitializerIndentWidth: 4
44+
ContinuationIndentWidth: 4
45+
Cpp11BracedListStyle: true
46+
DerivePointerAlignment: false
47+
DisableFormat: false
48+
ExperimentalAutoDetectBinPacking: false
49+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
50+
IncludeCategories:
51+
- Regex: '^<.*\.h>'
52+
Priority: 1
53+
- Regex: '^<.*'
54+
Priority: 2
55+
- Regex: '.*'
56+
Priority: 3
57+
IncludeIsMainRegex: '([-_](test|unittest))?$'
58+
IndentCaseLabels: true
59+
IndentWidth: 2
60+
IndentWrappedFunctionNames: false
61+
KeepEmptyLinesAtTheStartOfBlocks: false
62+
MacroBlockBegin: ''
63+
MacroBlockEnd: ''
64+
MaxEmptyLinesToKeep: 1
65+
NamespaceIndentation: All
66+
ObjCBlockIndentWidth: 2
67+
ObjCSpaceAfterProperty: false
68+
ObjCSpaceBeforeProtocolList: false
69+
PenaltyBreakBeforeFirstCallParameter: 1
70+
PenaltyBreakComment: 300
71+
PenaltyBreakFirstLessLess: 120
72+
PenaltyBreakString: 1000
73+
PenaltyExcessCharacter: 1000000
74+
PenaltyReturnTypeOnItsOwnLine: 200
75+
PointerAlignment: Left
76+
ReflowComments: false
77+
SortIncludes: true
78+
SpaceAfterCStyleCast: false
79+
SpaceBeforeAssignmentOperators: true
80+
SpaceBeforeParens: ControlStatements
81+
SpaceInEmptyParentheses: false
82+
SpacesBeforeTrailingComments: 2
83+
SpacesInAngles: false
84+
SpacesInContainerLiterals: false
85+
SpacesInCStyleCastParentheses: false
86+
SpacesInParentheses: false
87+
SpacesInSquareBrackets: false
88+
Standard: Cpp11
89+
TabWidth: 4
90+
UseTab: Never
91+
JavaScriptQuotes: Leave
92+
...

.github/pre-commit.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: pre-commit
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
pre-commit:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: cvmfs-contrib/github-action-cvmfs@v2
11+
- uses: aidasoft/run-lcg-view@v3
12+
with:
13+
release-platform: LCG_101/x86_64-centos7-clang12-opt
14+
run: |
15+
export PYTHONPATH=$(python -m site --user-site):$PYTHONPATH
16+
export PATH=/root/.local/bin:$PATH
17+
pip install --upgrade --user pip
18+
pip install argparse --user
19+
pip install pre-commit --user
20+
pre-commit run --show-diff-on-failure \
21+
--color=always \
22+
--all-files

.github/scripts/clang-format-hook

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Thin wrapper around clang-format for easier to parse output from the
4+
# pre-commit hook.
5+
#
6+
# Needs to work with multiple input files as pre-commit passes multiple files to
7+
# the "executables"
8+
9+
# Make sure that diff is actually recent enough (diffutils >= 3.4) to support
10+
# colored output
11+
COLOR_OUTPUT=$(diff --color=always <(echo) <(echo) > /dev/null 2>&1 && echo "--color=always")
12+
13+
success=0
14+
for file in ${@}; do
15+
if ! $(clang-format --style=file --Werror --dry-run ${file} > /dev/null 2>&1); then
16+
echo "Necessary changes for: '${file}' (run 'clang-format --style=file -i ${file}' to fix it)"
17+
diff ${COLOR_OUTPUT} -u ${file} <(clang-format --style=file ${file}) | tail -n +3
18+
success=1
19+
fi
20+
done
21+
exit ${success}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ CTestTestfile.cmake
5757
CPackSourceConfig.cmake
5858
CPackConfig.cmake
5959
cmake_install.cmake
60+
/compile_commands.json
61+
/.clangd/

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.4.0
4+
hooks:
5+
- id: mixed-line-ending
6+
- id: trailing-whitespace
7+
exclude: (doc/ReleaseNotes.md)
8+
- repo: local
9+
hooks:
10+
- id: clang-format
11+
name: clang-format
12+
entry: .github/scripts/clang-format-hook
13+
types: [c++]
14+
language: system

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ k4FWCore is a Gaudi package that provides the PodioDataService, that allows to
1313
Component wrapping the PodioDataService to handle PODIO types and collections.
1414

1515

16-
#### PodioInput
16+
#### PodioInput
1717

18-
Algorithm to read data from input file(s) on disk.
18+
Algorithm to read data from input file(s) on disk.
1919

2020
#### PodioOutput
2121

2222
Algorithm to write data to output file on disk.
2323

2424
#### FWFloatProducer
2525

26-
Algorithm with a simple float as output, for testing and adding parameters to jobs.
26+
Algorithm with a simple float as output, for testing and adding parameters to jobs.
2727

2828

2929
## Dependencies
@@ -36,7 +36,7 @@ Algorithm with a simple float as output, for testing and adding parameters to jo
3636

3737
## Installation and downstream usage.
3838

39-
k4FWCore is a cmake project. After setting up the dependencies (use for example `source /cvmfs/sw.hsf.org/key4hep/setup.sh`)
39+
k4FWCore is a cmake project. After setting up the dependencies (use for example `source /cvmfs/sw.hsf.org/key4hep/setup.sh`)
4040

4141

4242
```

k4FWCore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install(TARGETS k4FWCore k4FWCorePlugins
3131
COMPONENT dev)
3232

3333

34-
add_test(NAME WriteTest
34+
add_test(NAME WriteTest
3535
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
3636
COMMAND ${CMAKE_BINARY_DIR}/run ${PROJECT_SOURCE_DIR}/k4FWCore/scripts/k4run k4FWCore/test/options/simple_write.py)
3737

k4FWCore/components/FCCDataSvc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
/// an alias to k4DataSvc for backwards compatibility
88
class FCCDataSvc : public PodioDataSvc {
9-
109
public:
1110
/// Standard Constructor
1211
FCCDataSvc(const std::string& name, ISvcLocator* svc);

k4FWCore/components/PodioInput.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ DECLARE_COMPONENT(PodioInput)
1111
PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {}
1212

1313
StatusCode PodioInput::initialize() {
14-
if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE;
14+
if (GaudiAlgorithm::initialize().isFailure())
15+
return StatusCode::FAILURE;
1516

1617
// check whether we have the PodioEvtSvc active
1718
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(evtSvc().get());
18-
if (nullptr == m_podioDataSvc) return StatusCode::FAILURE;
19+
if (nullptr == m_podioDataSvc)
20+
return StatusCode::FAILURE;
1921

2022
auto idTable = m_podioDataSvc->getCollectionIDs();
2123
for (auto& name : m_collectionNames) {
@@ -45,6 +47,7 @@ StatusCode PodioInput::execute() {
4547
}
4648

4749
StatusCode PodioInput::finalize() {
48-
if (GaudiAlgorithm::finalize().isFailure()) return StatusCode::FAILURE;
50+
if (GaudiAlgorithm::finalize().isFailure())
51+
return StatusCode::FAILURE;
4952
return StatusCode::SUCCESS;
5053
}

k4FWCore/components/PodioInput.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
// from k4FWCore:
1212
class PodioDataSvc;
1313

14-
/** @class PodioInput
14+
/** @class PodioInput
1515
*
1616
* Class that allows to read ROOT files written with PodioOutput
1717
*
1818
* @author J. Lingemann
1919
*/
2020

2121
class PodioInput : public GaudiAlgorithm {
22-
2322
public:
2423
/// Constructor.
2524
PodioInput(const std::string& name, ISvcLocator* svcLoc);

0 commit comments

Comments
 (0)