Skip to content
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

Modernize clang-format file #342

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
# The branches below must be a subset of the branches above
branches: [ "master" ]

# abort old runs if a new one is started
concurrency:
group: ${{ github.head_ref }}-codeql-test
cancel-in-progress: true

jobs:
analyze:
name: Analyze
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# get current state from git
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get doxygen
run: sudo apt-get install doxygen -y
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/ls1_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: clang-format check for ls1

on:
push:
# pushes to master
branches: [ master ]
pull_request:
# PRs to master
branches: [ master ]

# abort old runs if a new one is started
concurrency:
group: ${{ github.head_ref }}-format-test
cancel-in-progress: true

jobs:
clang-format-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install clang-format (Version 18)
run: sudo apt-get install -y clang-format-18

- name: Run clang-format and check for differences
run: |
# Run clang-format and get changes
clang-format-18 -i $(find src -name "*.h" -or -name "*.cpp")
git diff --name-only > diff_files.log

- name: Check changes
id: check_diff
run: |
if [ -s diff_files.log ]; then
echo "Formatting issues detected!"
echo "formatting_issues=true" >> "$GITHUB_ENV"
else
echo "No formatting issues found"
echo "formatting_issues=false" >> "$GITHUB_ENV"
fi

# - name: Post comment if issues found
# if: env.formatting_issues == 'true'
# uses: actions/github-script@v7
# with:
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: ':warning: The CI detected formatting issues in this pull request. '
# + 'Please run clang-format (version 18) locally to resolve them.\n'
# + 'Details are shown in the [job log](https://github.com/'
# + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId + ').'
# })

- name: Exit with failure if clang-format found issues
if: env.formatting_issues == 'true'
run: |
echo "#### :warning: Formatting issues detected!" >> $GITHUB_STEP_SUMMARY
echo "Format the following files properly:" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat diff_files.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# exit 1
2 changes: 1 addition & 1 deletion .github/workflows/ls1_staticCodeAnalysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
static_analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ls1_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

# abort old runs if a new one is started
concurrency:
group: ${{ github.head_ref }}-tests
group: ${{ github.head_ref }}-build-tests
cancel-in-progress: true

jobs:
Expand Down
19 changes: 19 additions & 0 deletions cmake/modules/clangformat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Find clang-format
find_program(CLANG_FORMAT_BIN clang-format)

if (NOT CLANG_FORMAT_BIN)
message(FATAL_ERROR "clang-format not found!")
endif()

# Recursively find all files with the specified extensions
file(GLOB_RECURSE ALL_SOURCE_FILES
${PROJECT_SOURCE_DIR}/*.h
${PROJECT_SOURCE_DIR}/*.cpp
)

# Define clang-format target
add_custom_target(clang-format
COMMAND ${CLANG_FORMAT_BIN} -i ${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Running clang-format"
)
4 changes: 4 additions & 0 deletions makefile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ help_vect:

all: $(BINARY)

clangformat:
@echo "Running clang-format (version might not match the one of the CI which uses v18)"
@echo "$(shell clang-format --version)"
clang-format -i $(shell find $(SRCDIR) -name "*.h" -or -name "*.cpp")

#list available configurations
cfg_list:
Expand Down
119 changes: 14 additions & 105 deletions src/.clang-format
Original file line number Diff line number Diff line change
@@ -1,108 +1,17 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BasedOnStyle: Google
AccessModifierOffset: -4 #-2
AllowShortBlocksOnASingleLine: Empty #Never
AllowShortIfStatementsOnASingleLine: Never #Never
AllowShortLoopsOnASingleLine: false #false
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: ForContinuationAndIndentation
...

ColumnLimit: 120 #80
IncludeBlocks: Regroup
IndentCaseLabels: true #false
IndentWidth: 4 #2
ObjCBlockIndentWidth: 4 #2
PenaltyReturnTypeOnItsOwnLine: 2000000 #tries to force function return type and function name to be on the same line, default 200 (google)
PointerAlignment: Left #Right
TabWidth: 4 #8
UseTab: Always #Never
Loading